summaryrefslogtreecommitdiffstats
path: root/funtools/fitsy/ftacht2.c
blob: a4d2ec3e594ee6e130400f5d058eb7c74a9eff20 (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* ft_acht2.c
**
** Vector change type operators.
** FITS adds bzero and bascle.
**/

#if HAVE_CONFIG_H
#include <conf.h>
#endif
#include "xos.h"
#include "fitsy.h"
#include "longlong.h"
#include "generic.h"

typedef void (*vector)();

#ifdef __STDC__
#define cht2xx(ch1, type1, ch2, type2)					\
									\
void cht2##ch1##ch2(v1, v2, npix, rtn, direction)			\
			void	*v1;					\
			void	*v2;					\
			int	npix;					\
			vector  rtn;					\
			int	direction;				\
{									\
  type1 tval1;								\
  type2 tval2;								\
  if( direction == 0 ){							\
    while ( npix-- ) {							\
      (rtn)(&tval2, (char *)v2+(npix*sizeof(type2)), sizeof(type2));	\
      tval1 = tval2;							\
      memcpy((char *)v1+(npix*sizeof(type1)), &tval1, sizeof(type1));	\
    }									\
  }									\
  else{									\
    while ( npix-- ) {							\
      memcpy(&tval2, (char *)v2+(npix*sizeof(type2)), sizeof(type2));	\
      tval1 = tval2;							\
      (rtn)((char *)v1+(npix*sizeof(type1)), &tval1, sizeof(type1));	\
    }									\
  }									\
}
#else
#define cht2xx(ch1, type1, ch2, type2)					\
									\
void cht2/**/ch1/**/ch2(v1, v2, npix, rtn, direction)			\
			void    *v1;					\
			void	*v2;					\
			int	npix;					\
			vector  rtn;					\
			int	direction;				\
{									\
  type1 tval1;								\
  type2 tval2;								\
  if( direction == 0 ){							\
    while ( npix-- ) {							\
      (rtn)(&tval2, (char *)v2+(npix*sizeof(type2)), sizeof(type2));	\
      tval1 = tval2;							\
      memcpy((char *)v1+(npix*sizeof(type1)), &tval1, sizeof(type1));	\
    }									\
  }									\
  else{									\
    while ( npix-- ) {							\
      memcpy(&tval2, (char *)v2+(npix*sizeof(type2)), sizeof(type2));	\
      tval1 = tval2;							\
      (rtn)((char *)v1+(npix*sizeof(type1)), &tval1, sizeof(type1));	\
    }									\
  }									\
}
#endif

DOUBLE_GENERIC(cht2xx)

static int pixtype2(type)
	int	type;
{
    switch ( type ) {
     case 'A':			return TY_UCHAR;
     case 'B':			return TY_UCHAR;
     case 'X':			return TY_UCHAR;
     case 'I':			return TY_SHORT;
     case 'K':			return TY_LONG;
     case 'U':			return TY_USHORT;
     case 'J':			return TY_INT;
     case 'V':			return TY_UINT;
     case 'L':			return TY_UCHAR;
     case 'E':			return TY_REAL;
     case 'D':			return TY_DOUBLE;
    }

    return -1;
}

void ft_acht2(type1, v1, type2, v2, npix, swap, direction)
			int	type1;
			void*	v1;
			int	type2;
			void*	v2;
			int	npix;
			int     swap;
			int	direction;
{
		vector rtn=NULL;
		int offset1, offset2, type;

static vector matrix[10][10] = {
      { cht2cc,cht2cs,cht2ci,cht2cl,cht2cr,cht2cd,cht2ct,cht2cu,cht2cv }
    , { cht2sc,cht2ss,cht2si,cht2sl,cht2sr,cht2sd,cht2st,cht2su,cht2sv }
    , { cht2ic,cht2is,cht2ii,cht2il,cht2ir,cht2id,cht2it,cht2iu,cht2iv }
    , { cht2lc,cht2ls,cht2li,cht2ll,cht2lr,cht2ld,cht2lt,cht2lu,cht2lv }
    , { cht2rc,cht2rs,cht2ri,cht2rl,cht2rr,cht2rd,cht2rt,cht2ru,cht2rv }
    , { cht2dc,cht2ds,cht2di,cht2dl,cht2dr,cht2dd,cht2dt,cht2du,cht2dv }
    , { cht2tc,cht2ts,cht2ti,cht2tl,cht2tr,cht2td,cht2tt,cht2tu,cht2tv }
    , { cht2uc,cht2us,cht2ui,cht2ul,cht2ur,cht2ud,cht2ut,cht2uu,cht2uv }
    , { cht2vc,cht2vs,cht2vi,cht2vl,cht2vr,cht2vd,cht2vt,cht2vu,cht2vv }
};

    offset1 = pixtype2(type1);
    offset2 = pixtype2(type2);
    if ( offset1 < 0 || offset2 < 0 ) return;

    if( swap ){
      if( direction == 0 )
	type = type2;
      else
	type = type1;
      switch(ft_sizeof(type)){
      case 1:
	rtn = (vector)memcpy;
	break;
      case 2:
	rtn = swap2;
	break;
      case 4:
	rtn = swap4;
	break;
      case 8:
	rtn = swap8;
	break;
      default:
	rtn = (vector)memcpy;
	break;
      }
    }
    else{
      rtn = (vector)memcpy;
    }

    (*matrix[offset1][offset2])(v1, v2, npix, rtn, direction);
}