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
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <ctype.h>
include "wcspix.h"
# Unknown class data.
define LEN_UNKDATA 1
define UNK_WP Memi[$1 ] # wcspix back-pointer
# UNK_INIT -- Initialize the object structure.
procedure unk_init (cp, wp)
pointer cp #i cache pointer
pointer wp #i WCSPIX structure
begin
# Allocate the image data structure if not previously allocated.
if (C_DATA(cp) == NULL) {
iferr (call calloc (C_DATA(cp), LEN_UNKDATA, TY_STRUCT))
return
}
UNK_WP(C_DATA(cp)) = wp
end
# UNK_CACHE -- Cache an image in the object cache. Since we don't know
# what this is we simply setup so that a query to the object id will still
# return a result of some kind rather than ignore it. In most cases this
# just means the input arguments are echoed back (e.g. coords), or default
# values such as a rotation value can be retrieved.
procedure unk_cache (cp, objid, regid, ref)
pointer cp #i cache pointer
int objid #i object id
int regid #i region id
char ref[ARB] #i object reference
begin
C_OBJID(cp) = objid
C_REGID(cp) = regid
C_NREF(cp) = C_NREF(cp) + 1
call strcpy (ref, C_REF(cp), 128)
end
# UNK_UNCACHE -- Uncache an unknown image in the object cache.
procedure unk_uncache (cp, id)
pointer cp #i cache pointer
int id #i image id
begin
C_OBJID(cp) = NULL
C_NREF(cp) = 0
call strcpy ("", C_REF(cp), SZ_FNAME)
call mfree (C_DATA(cp), TY_STRUCT)
C_DATA(cp) = NULL
end
# UNK_WCSTRAN -- Translate object source (x,y) coordinates to the
# desired output WCSs. Message is returned as something like:
#
# set value {
# { object <objid> } { region <regionid> }
# { pixval <pixelvalue> [<units>] }
# { coord <wcsname> <x> <y> [<xunits> <yunits>] }
# { coord <wcsname> <x> <y> [<xunits> <yunits>] }
# }
procedure unk_wcstran (cp, id, x, y)
pointer cp #i cache pointer
int id #i image id
real x, y #i source coords
pointer wp
int i
# Use static storage to avoid allocation overhead.
char buf[SZ_LINE], msg[SZ_LINE]
begin
wp = UNK_WP(C_DATA(cp))
# Begin formatting the message.
call aclrc (msg, SZ_LINE)
call sprintf (msg, SZ_LINE, "wcstran { object %d } { region %d } ")
call pargi (C_OBJID(cp))
call pargi (C_REGID(cp))
call strcat ("{ pixval 0.0 } { bpm 0 } \n", msg, SZ_LINE)
# Now loop over the requested systems and generate a coordinate
# for each.
for (i=1; i <= MAX_WCSLINES; i=i+1) {
# Format the coord buffer and append it to the message.
call sprintf (buf, SZ_LINE, "{coord {%9s} {%12g} {%12g} {X} {Y}}\n")
call pargstr ("UNKN")
call pargr (x)
call pargr (y)
call strcat (buf, msg, SZ_LINE)
}
# Now send the completed message.
call wcspix_message (msg)
end
# UNK_WCSLIST -- List the WCSs available for the given image.
procedure unk_wcslist (cp, id)
pointer cp #i cache pointer
int id #i image id
begin
#call wcspix_message ("wcslist {None Logical}")
end
# UNK_GETDATA -- Get data from the image.
procedure unk_getdata (cp, id, x, y, pixval)
pointer cp #i cache pointer
int id #i image id
real x, y #i source coords
real pixval #o central pixel value
pointer wp, pix
int size, x1, x2, y1, y2
begin
wp = UNK_WP(C_DATA(cp))
size = WP_PTABSZ(wp)
# Compute the box offset given the center and size.
x1 = x - size / 2 + 0.5
x2 = x + size / 2 + 0.5
y1 = y - size / 2 + 0.5
y2 = y + size / 2 + 0.5
pixval = 0.0
# Send the pixel table.
if (size > 1) {
call calloc (pix, size * size, TY_REAL)
call img_send_pixtab (Memr[pix], size, x1, x2, y1, y2)
call mfree (pix, TY_REAL)
}
end
# UNK_OBJINFO -- Get header information from the image.
procedure unk_objinfo (cp, id, template)
pointer cp #i cache pointer
int id #i image id
char template[ARB] #i keyword template
pointer sp, buf
begin
call smark (sp)
call salloc (buf, SZ_LINE, TY_CHAR)
# Send a default (X,Y) compass indicator.
call aclrc (Memc[buf], SZ_LINE)
call sprintf (Memc[buf], SZ_LINE, "compass %d 0.0 -1 1 X Y\0")
call pargi (C_OBJID(cp))
call wcspix_message (Memc[buf])
call sfree (sp)
end
|