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
|
include <smw.h>
# Evaluate SMW coordinate transform. These procedures call the
# MWCS procedures unless the WCS is a split MULTISPEC WCS. In that
# case the appropriate piece needs to be determined and the physical
# line numbers manipulated. For log sampled spectra conversions
# must be made for EQUISPEC/NDSPEC. The convention is that coordinates
# are always input and output and linear. Note that the MULTISPEC
# function driver already takes care of this.
#
# SMW_CTRANR -- N dimensional real coordinate transformation.
# SMW_CTRAND -- N dimensional double coordinate transformation.
# SMW_C1TRANR -- One dimensional real coordinate transformation.
# SMW_C1TRAND -- One dimensional double coordinate transformation.
# SMW_C2TRANR -- Two dimensional real coordinate transformation.
# SMW_C2TRAND -- Two dimensional double coordinate transformation.
# SMW_CTRAN -- N dimensional coordinate transformation.
procedure smw_ctranr (ct, p1, p2, ndim)
pointer ct #I SMW CT pointer
real p1[ndim] #I Input coordinate
real p2[ndim] #O Output coordinate
int ndim #I Dimensionality
int i, j, format, daxis, aaxis, dtype, naps
pointer smw, aps
errchk mw_ctranr
begin
if (SMW_NCT(ct) != 1)
call error (1, "SMW_CTRAN: Wrong WCS type")
call amovr (p1, p2, ndim)
smw = SMW_SMW(ct)
format = SMW_FORMAT(smw)
daxis = SMW_DAXIS(ct)
aaxis = SMW_AAXIS(ct)
dtype = SMW_DTYPE(smw)
naps = SMW_NSPEC(smw)
aps = SMW_APS(smw)
switch (format) {
case SMW_ND, SMW_ES:
switch (SMW_CTTYPE(ct)) {
case SMW_LW, SMW_PW:
call mw_ctranr (SMW_CT(ct,0), p2, p2, ndim)
if (daxis > 0 && dtype == DCLOG)
p2[daxis] = 10. ** max (-20.0, min (20.0, p2[daxis]))
if (aaxis > 0 && format == SMW_ES) {
i = max (1, min (naps, nint (p2[aaxis])))
p2[aaxis] = Memi[aps+i-1]
}
case SMW_WL, SMW_WP:
if (daxis > 0 && dtype == DCLOG)
p2[daxis] = log10 (p2[daxis])
if (aaxis > 0 && format == SMW_ES) {
j = nint (p2[aaxis])
p2[aaxis] = 1
do i = 1, naps {
if (j == Memi[aps+i-1]) {
p2[aaxis] = i
break
}
}
}
call mw_ctranr (SMW_CT(ct,0), p2, p2, ndim)
default:
call mw_ctranr (SMW_CT(ct,0), p2, p2, ndim)
}
case SMW_MS:
call mw_ctranr (SMW_CT(ct,0), p1, p2, ndim)
}
end
# SMW_C1TRAN -- One dimensional coordinate transformation.
real procedure smw_c1tranr (ct, x1)
pointer ct #I SMW CT pointer
real x1 #I Input coordinate
real x2 #O Output coordinate
errchk mw_ctranr
begin
call smw_ctranr (ct, x1, x2, 1)
return (x2)
end
# SMW_C2TRAN -- Two dimensional coordinate transformation.
procedure smw_c2tranr (ct, x1, y1, x2, y2)
pointer ct #I SMW CT pointer
real x1, y1 #I Input coordinates
real x2, y2 #O Output coordinates
real p1[2], p2[2]
int i, j, naps
real xp, yp
pointer aps, smw_ct()
errchk smw_ct, mw_c2tranr
begin
# Unsplit WCS.
if (SMW_NCT(ct) == 1) {
p1[1] = x1
p1[2] = y1
call smw_ctranr (ct, p1, p2, 2)
x2 = p2[1]
y2 = p2[2]
return
}
# If we get here then we are dealing with a split MULTISPEC WCS.
# Depending on the systems being transformed there may need to
# transformation made on the physical coordinate system.
switch (SMW_CTTYPE(ct)) {
case SMW_LW:
call mw_c2tranr (SMW_CTL(ct), x1, y1, xp, yp)
i = nint (yp)
yp = mod (i-1, SMW_NSPLIT) + 1
call mw_c2tranr (smw_ct(ct,i), xp, yp, x2, y2)
case SMW_PW:
i = nint (y1)
yp = mod (i-1, SMW_NSPLIT) + 1
call mw_c2tranr (smw_ct(ct,i), x1, yp, x2, y2)
case SMW_WL:
aps = SMW_APS(SMW_SMW(ct))
naps = SMW_NSPEC(SMW_SMW(ct))
j = nint (y1)
do i = 1, naps {
if (Memi[aps+i-1] == j) {
call mw_c2tranr (smw_ct(ct,i), x1, y1, xp, yp)
yp = i
call mw_c2tranr (SMW_CTL(ct), xp, yp, x2, y2)
return
}
}
call error (1, "Aperture not found")
case SMW_WP:
aps = SMW_APS(SMW_SMW(ct))
naps = SMW_NSPEC(SMW_SMW(ct))
j = nint (y1)
do i = 1, naps {
if (Memi[aps+i-1] == j) {
call mw_c2tranr (smw_ct(ct,i), x1, y1, x2, y2)
y2 = i
return
}
}
call error (1, "Aperture not found")
default:
x2 = x1
y2 = y1
}
end
# SMW_CTRAN -- N dimensional coordinate transformation.
procedure smw_ctrand (ct, p1, p2, ndim)
pointer ct #I SMW CT pointer
double p1[ndim] #I Input coordinate
double p2[ndim] #O Output coordinate
int ndim #I Dimensionality
int i, j, format, daxis, aaxis, dtype, naps
pointer smw, aps
errchk mw_ctrand
begin
if (SMW_NCT(ct) != 1)
call error (1, "SMW_CTRAN: Wrong WCS type")
call amovd (p1, p2, ndim)
smw = SMW_SMW(ct)
format = SMW_FORMAT(smw)
daxis = SMW_DAXIS(ct)
aaxis = SMW_AAXIS(ct)
dtype = SMW_DTYPE(smw)
naps = SMW_NSPEC(smw)
aps = SMW_APS(smw)
switch (format) {
case SMW_ND, SMW_ES:
switch (SMW_CTTYPE(ct)) {
case SMW_LW, SMW_PW:
call mw_ctrand (SMW_CT(ct,0), p2, p2, ndim)
if (daxis > 0 && dtype == DCLOG)
p2[daxis] = 10. ** max (-20.0D0, min (20.0D0, p2[daxis]))
if (aaxis > 0 && format == SMW_ES) {
i = max (1, min (naps, nint (p2[aaxis])))
p2[aaxis] = Memi[aps+i-1]
}
case SMW_WL, SMW_WP:
if (daxis > 0 && dtype == DCLOG)
p2[daxis] = log10 (p2[daxis])
if (aaxis > 0 && format == SMW_ES) {
j = nint (p2[aaxis])
p2[aaxis] = 1
do i = 1, naps {
if (j == Memi[aps+i-1]) {
p2[aaxis] = i
break
}
}
}
call mw_ctrand (SMW_CT(ct,0), p2, p2, ndim)
default:
call mw_ctrand (SMW_CT(ct,0), p2, p2, ndim)
}
case SMW_MS:
call mw_ctrand (SMW_CT(ct,0), p1, p2, ndim)
}
end
# SMW_C1TRAN -- One dimensional coordinate transformation.
double procedure smw_c1trand (ct, x1)
pointer ct #I SMW CT pointer
double x1 #I Input coordinate
double x2 #O Output coordinate
errchk mw_ctrand
begin
call smw_ctrand (ct, x1, x2, 1)
return (x2)
end
# SMW_C2TRAN -- Two dimensional coordinate transformation.
procedure smw_c2trand (ct, x1, y1, x2, y2)
pointer ct #I SMW CT pointer
double x1, y1 #I Input coordinates
double x2, y2 #O Output coordinates
double p1[2], p2[2]
int i, j, naps
double xp, yp
pointer aps, smw_ct()
errchk smw_ct, mw_c2trand
begin
# Unsplit WCS.
if (SMW_NCT(ct) == 1) {
p1[1] = x1
p1[2] = y1
call smw_ctrand (ct, p1, p2, 2)
x2 = p2[1]
y2 = p2[2]
return
}
# If we get here then we are dealing with a split MULTISPEC WCS.
# Depending on the systems being transformed there may need to
# transformation made on the physical coordinate system.
switch (SMW_CTTYPE(ct)) {
case SMW_LW:
call mw_c2trand (SMW_CTL(ct), x1, y1, xp, yp)
i = nint (yp)
yp = mod (i-1, SMW_NSPLIT) + 1
call mw_c2trand (smw_ct(ct,i), xp, yp, x2, y2)
case SMW_PW:
i = nint (y1)
yp = mod (i-1, SMW_NSPLIT) + 1
call mw_c2trand (smw_ct(ct,i), x1, yp, x2, y2)
case SMW_WL:
aps = SMW_APS(SMW_SMW(ct))
naps = SMW_NSPEC(SMW_SMW(ct))
j = nint (y1)
do i = 1, naps {
if (Memi[aps+i-1] == j) {
call mw_c2trand (smw_ct(ct,i), x1, y1, xp, yp)
yp = i
call mw_c2trand (SMW_CTL(ct), xp, yp, x2, y2)
return
}
}
call error (1, "Aperture not found")
case SMW_WP:
aps = SMW_APS(SMW_SMW(ct))
naps = SMW_NSPEC(SMW_SMW(ct))
j = nint (y1)
do i = 1, naps {
if (Memi[aps+i-1] == j) {
call mw_c2trand (smw_ct(ct,i), x1, y1, x2, y2)
y2 = i
return
}
}
call error (1, "Aperture not found")
default:
x2 = x1
y2 = y1
}
end
|