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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
|
// Copyright (C) 1999-2018
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"
#include "wcsast.h"
int wcsSystem(AstFrameSet* ast, Coord::CoordSystem sys)
{
int nn = astGetI(ast,"nframe");
char cc = ' ';
int ww = sys-Coord::WCS;
if (ww < 0)
return 0;
if (ww)
cc = ww+'@';
for (int ss=0; ss<nn; ss++) {
const char* id = astGetC(astGetFrame(ast,ss+1),"Ident");
if (cc == id[0]) {
astSetI(ast,"Current",ss+1);
return 1;
}
}
return 0;
}
void wcsSkyFrame(AstFrameSet* ast, Coord::SkyFrame sky)
{
// Asssume the current frame is an Equatoral SkyFrame
// must be checked else where
switch (sky) {
case Coord::FK4:
astSet(ast, "System=FK4, Equinox=B1950");
break;
case Coord::FK5:
astSet(ast, "System=FK5, Equinox=J2000");
break;
case Coord::ICRS:
astSet(ast, "System=ICRS");
break;
case Coord::GALACTIC:
astSet(ast, "System=GALACTIC");
break;
case Coord::ECLIPTIC:
astSet(ast, "System=ECLIPTIC");
// get AST to agree with WCSSUBS
astSetD(ast, "EQUINOX", astGetD(ast, "EPOCH"));
break;
}
}
void wcsFormat(AstFrameSet* ast, int id, const char* format)
{
// is it already set?
// ast is very slow when changing params
{
ostringstream str;
str << "Format(" << id << ")" << ends;
const char* out = astGetC(ast, str.str().c_str());
if (!strcmp(out,format))
return;
}
ostringstream str;
str << "Format(" << id << ")=" << format << ends;
astSet(ast, str.str().c_str());
}
Vector wcsTran(AstFrameSet* ast, const Vector& in, int forward)
{
int naxes = astGetI(ast,"Naxes");
switch (naxes) {
case 1:
// error
break;
case 2:
double xout, yout;
astTran2(ast, 1, in.v, in.v+1, forward, &xout, &yout);
return Vector(xout, yout);
case 3:
{
double pin[3];
double pout[3];
pin[0] = in[0];
pin[1] = in[1];
pin[2] = forward ? 1 : 0;
astTranN(ast, 1, 3, 1, pin, forward, 3, 1, pout);
return Vector(pout[0],pout[1]);
}
break;
case 4:
{
double pin[4];
double pout[4];
pin[0] = in[0];
pin[1] = in[1];
pin[2] = forward ? 1 : 0;
pin[3] = forward ? 1 : 0;
astTranN(ast, 1, 4, 1, pin, forward, 4, 1, pout);
return Vector(pout[0],pout[1]);
}
break;
}
return Vector();
}
void wcsTran(AstFrameSet* ast, int npoint, Vector* in, int forward, Vector* out)
{
int naxes = astGetI(ast,"Naxes");
switch (naxes) {
case 1:
// error
break;
case 2:
{
double* xin = new double[npoint];
double* yin = new double[npoint];
double* xout = new double[npoint];
double* yout = new double[npoint];
for (int ii=0; ii<npoint; ii++) {
xin[ii] = in[ii][0];
yin[ii] = in[ii][1];
}
astTran2(ast, npoint, xin, yin, forward, xout, yout);
for (int ii=0; ii<npoint; ii++)
out[ii] = Vector(xout[ii],yout[ii]);
if (xin)
delete [] xin;
if (yin)
delete [] yin;
if (xout)
delete [] xout;
if (yout)
delete [] yout;
}
break;
case 3:
{
double* ptr_in[3];
ptr_in[0] = new double[npoint];
ptr_in[1] = new double[npoint];
ptr_in[2] = new double[npoint];
double* ptr_out[3];
ptr_out[0] = new double[npoint];
ptr_out[1] = new double[npoint];
ptr_out[2] = new double[npoint];
for (int kk=0; kk<npoint; kk++) {
ptr_in[0][kk] = in[kk][0];
ptr_in[1][kk] = in[kk][1];
ptr_in[2][kk] = forward ? 1 : 0;
}
astTranP(ast, npoint, 3, (const double**)ptr_in, forward, 3, ptr_out);
for (int kk=0; kk<npoint; kk++)
out[kk] = Vector(ptr_out[0][kk], ptr_out[1][kk]);
if (ptr_in[0])
delete [] ptr_in[0];
if (ptr_in[1])
delete [] ptr_in[1];
if (ptr_in[2])
delete [] ptr_in[2];
if (ptr_out[0])
delete [] ptr_out[0];
if (ptr_out[1])
delete [] ptr_out[1];
if (ptr_out[2])
delete [] ptr_out[2];
}
break;
case 4:
{
double* ptr_in[4];
ptr_in[0] = new double[npoint];
ptr_in[1] = new double[npoint];
ptr_in[2] = new double[npoint];
ptr_in[3] = new double[npoint];
double* ptr_out[4];
ptr_out[0] = new double[npoint];
ptr_out[1] = new double[npoint];
ptr_out[2] = new double[npoint];
ptr_out[3] = new double[npoint];
for (int kk=0; kk<npoint; kk++) {
ptr_in[0][kk] = in[kk][0];
ptr_in[1][kk] = in[kk][1];
ptr_in[2][kk] = forward ? 1 : 0;
ptr_in[3][kk] = forward ? 1 : 0;
}
astTranP(ast, npoint, 4, (const double**)ptr_in, forward, 4, ptr_out);
for (int kk=0; kk<npoint; kk++)
out[kk] = Vector(ptr_out[0][kk], ptr_out[1][kk]);
if (ptr_in[0])
delete [] ptr_in[0];
if (ptr_in[1])
delete [] ptr_in[1];
if (ptr_in[2])
delete [] ptr_in[2];
if (ptr_in[3])
delete [] ptr_in[3];
if (ptr_out[0])
delete [] ptr_out[0];
if (ptr_out[1])
delete [] ptr_out[1];
if (ptr_out[2])
delete [] ptr_out[2];
if (ptr_out[3])
delete [] ptr_out[3];
}
break;
}
}
Vector3d wcsTran(AstFrameSet* ast, const Vector3d& in, int forward)
{
int naxes = astGetI(ast,"Naxes");
switch (naxes) {
case 1:
case 2:
double pin[2];
double pout[2];
pin[0] = in[0];
pin[1] = in[1];
astTranN(ast, 1, 2, 1, pin, forward, 2, 1, pout);
return Vector3d(pout[0],pout[1],forward ? 1 : 0);
break;
case 3:
{
double pin[3];
double pout[3];
pin[0] = in[0];
pin[1] = in[1];
pin[2] = in[2];
astTranN(ast, 1, 3, 1, pin, forward, 3, 1, pout);
return Vector3d(pout[0],pout[1],pout[2]);
}
break;
case 4:
{
double pin[4];
double pout[4];
pin[0] = in[0];
pin[1] = in[1];
pin[2] = in[2];
pin[3] = forward ? 1 : 0;
astTranN(ast, 1, 4, 1, pin, forward, 4, 1, pout);
return Vector3d(pout[0],pout[1],pout[2]);
}
break;
}
return Vector3d();
}
double wcsDistance(AstFrameSet* ast, const Vector& vv1, const Vector& vv2)
{
int naxes = astGetI(ast,"Naxes");
switch (naxes) {
case 1:
// error
break;
case 2:
return astDistance(ast, vv1.v, vv2.v);
case 3:
{
double ptr1[3];
ptr1[0] = vv1[0];
ptr1[1] = vv1[1];
ptr1[2] = 0;
double ptr2[3];
ptr2[0] = vv2[0];
ptr2[1] = vv2[1];
ptr2[2] = 0;
return astDistance(ast, ptr1, ptr2);
}
case 4:
{
double ptr1[4];
ptr1[0] = vv1[0];
ptr1[1] = vv1[1];
ptr1[2] = 0;
ptr1[3] = 0;
double ptr2[4];
ptr2[0] = vv2[0];
ptr2[1] = vv2[1];
ptr2[2] = 0;
ptr2[3] = 0;
return astDistance(ast, ptr1, ptr2);
}
}
return 0;
}
double wcsAngle(AstFrameSet* ast, const Vector& vv1, const Vector& vv2,
const Vector& vv3)
{
int naxes = astGetI(ast,"Naxes");
switch (naxes) {
case 1:
// error
break;
case 2:
return astAngle(ast,vv1.v,vv2.v,vv3.v);
case 3:
{
double ptr1[3];
ptr1[0] = vv1[0];
ptr1[1] = vv1[1];
ptr1[2] = 0;
double ptr2[3];
ptr2[0] = vv2[0];
ptr2[1] = vv2[1];
ptr2[2] = 0;
double ptr3[3];
ptr3[0] = vv3[0];
ptr3[1] = vv3[1];
ptr3[2] = 0;
return astAngle(ast, ptr1, ptr2, ptr3);
}
case 4:
{
double ptr1[4];
ptr1[0] = vv1[0];
ptr1[1] = vv1[1];
ptr1[2] = 0;
ptr1[3] = 0;
double ptr2[4];
ptr2[0] = vv2[0];
ptr2[1] = vv2[1];
ptr2[2] = 0;
ptr2[3] = 0;
double ptr3[4];
ptr3[0] = vv3[0];
ptr3[1] = vv3[1];
ptr3[2] = 0;
ptr3[3] = 0;
return astAngle(ast, ptr1, ptr2, ptr3);
}
}
return 0;
}
double wcsAxAngle(AstFrameSet* ast, const Vector& vv1, const Vector& vv2)
{
int naxes = astGetI(ast,"Naxes");
switch (naxes) {
case 1:
// error
break;
case 2:
return astAxAngle(ast, vv1.v, vv2.v, 2);
case 3:
{
double ptr1[3];
ptr1[0] = vv1[0];
ptr1[1] = vv1[1];
ptr1[2] = 0;
double ptr2[3];
ptr2[0] = vv2[0];
ptr2[1] = vv2[1];
ptr2[2] = 0;
return astAxAngle(ast, ptr1, ptr2, 2);
}
case 4:
{
double ptr1[4];
ptr1[0] = vv1[0];
ptr1[1] = vv1[1];
ptr1[2] = 0;
ptr1[3] = 0;
double ptr2[4];
ptr2[0] = vv2[0];
ptr2[1] = vv2[1];
ptr2[2] = 0;
ptr2[3] = 0;
return astAxAngle(ast, ptr1, ptr2, 2);
}
}
return 0;
}
AstWinMap* wcsWinMap(AstFrameSet* ast, Vector& ll, Vector& ur, Vector& rr)
{
int naxes = astGetI(ast,"Naxes");
switch (naxes) {
case 1:
// error
return NULL;
case 2:
return astWinMap(2, ll.vv(), rr.vv(), ll.vv(), ur.vv(), "");
case 3:
{
double vll[3];
vll[0] = ll[0];
vll[1] = ll[0];
vll[2] = .5;
double vur[3];
vur[0] = ur[0];
vur[1] = ur[0];
vur[2] = .5;
double vrr[3];
vrr[0] = rr[0];
vrr[1] = rr[1];
vrr[2] = 1.5;
return astWinMap(3, vll, vrr, vll, vur, "");
}
case 4:
{
double vll[4];
vll[0] = ll[0];
vll[1] = ll[0];
vll[2] = .5;
vll[3] = .5;
double vur[4];
vur[0] = ur[0];
vur[1] = ur[0];
vur[2] = .5;
vur[3] = .5;
double vrr[4];
vrr[0] = rr[0];
vrr[1] = rr[1];
vrr[2] = 1.5;
vrr[3] = 1.5;
return astWinMap(4, vll, vrr, vll, vur, "");
}
break;
}
return NULL;
}
AstCmpMap* wcsMatrixMap(AstFrameSet* ast, Matrix& mx)
{
AstMatrixMap* mm =NULL;
AstShiftMap* sm =NULL;
int naxes = astGetI(ast,"Naxes");
switch (naxes) {
case 1:
// error
return NULL;
case 2:
{
double ss[] = {mx.matrix(0,0),mx.matrix(1,0),
mx.matrix(0,1),mx.matrix(1,1)};
double tt[] = {mx.matrix(2,0),mx.matrix(2,1)};
mm = astMatrixMap(2, 2, 0, ss, "");
sm = astShiftMap(2, tt, "");
}
break;
case 3:
{
double ss[] = {mx.matrix(0,0),mx.matrix(1,0),0,
mx.matrix(0,1),mx.matrix(1,1),0,
0,0,1};
double tt[] = {mx.matrix(2,0),mx.matrix(2,1),0};
mm = astMatrixMap(3, 3, 0, ss, "");
sm = astShiftMap(3, tt, "");
}
break;
case 4:
{
double ss[] = {mx.matrix(0,0),mx.matrix(1,0),0,0,
mx.matrix(0,1),mx.matrix(1,1),0,0,
0,0,1,0,
0,0,0,1};
double tt[] = {mx.matrix(2,0),mx.matrix(2,1),0,0};
mm = astMatrixMap(4, 4, 0, ss, "");
sm = astShiftMap(4, tt, "");
}
break;
}
if (mm && sm)
return astCmpMap(mm, sm, 1, "");
else
return NULL;
}
|