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
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <ctype.h>
include "zdisplay.h"
include "iis.h"
# IMD_GETWCS -- Get the saved WCS for the given frame of the given display
# device. (No great attempt at generality here).
# [INTERNAL ROUTINE - RESTRICTED USE].
#
# Example:
#
# dev$pix - m51 B 600s
# 1. 0. 0. -1. 1. 512. 36. 320.0713 1
#
# The file format is the image title, followed by a line specifying the
# coordinate transformation matrix (6 numbers: a b c d tx ty) and the
# greyscale transformation (z1 z2 zt).
#
# The procedure returns OK if the WCS for the frame is sucessfully accessed,
# or ERR if the WCS cannot be read. In the latter case the output WCS will
# be the default unitary WCS.
int procedure imd_getwcs (frame, server, image, sz_image, title, sz_title,
a, b, c, d, tx, ty)
int frame #I frame (wcs) number of current device
int server #I device is a display server
char image[ARB] #O image name
int sz_image #I max image name length
char title[ARB] #O image title string
int sz_title #I max image title length
real a, d #O x, y scale factors
real b, c #O cross terms (rotations)
real tx, ty #O x, y offsets
char ch
int fd, chan, status, wcs_status, zt
real z1, z2
pointer sp, dir, device, fname, wcstext
int envfind(), strncmp(), open(), fscan(), nscan(), stropen(), iisflu()
include "iis.com"
begin
call smark (sp)
call salloc (dir, SZ_PATHNAME, TY_CHAR)
call salloc (fname, SZ_PATHNAME, TY_CHAR)
call salloc (device, SZ_FNAME, TY_CHAR)
call salloc (wcstext, SZ_WCSTEXT, TY_CHAR)
wcs_status = OK
# Retrieve the WCS text and open a file descriptor on it.
if (server == YES) {
# Retrieve the WCS information from a display server.
chan = iisflu(FRTOCHAN(frame))
# Cannot use iisio here as the data is byte packed and cannot be
# swapped (while the header still has to be swapped).
if (iis_version > 0) {
iis_valid = NO
call iishdr (IREAD+PACKED, SZ_WCSTEXT, WCS, 1, 0, chan, 0)
call iisio (Memc[wcstext], SZ_WCSTEXT, status)
if (status > 0)
call strupk (Memc[wcstext], Memc[wcstext], SZ_WCSTEXT)
iferr (fd = stropen (Memc[wcstext], SZ_WCSTEXT, READ_ONLY))
fd = NULL
} else {
call iishdr (IREAD+PACKED, SZ_OLD_WCSTEXT, WCS, 0, 0, chan, 0)
call iisio (Memc[wcstext], SZ_OLD_WCSTEXT, status)
if (status > 0)
call strupk (Memc[wcstext], Memc[wcstext], SZ_OLD_WCSTEXT)
iferr (fd = stropen (Memc[wcstext], SZ_OLD_WCSTEXT, READ_ONLY))
fd = NULL
}
} else {
# Construct the WCS filename, "dir$device_frame.wcs". (Copied from
# the make-WCS code in t_display.x).
if (envfind ("wcsdir", Memc[dir], SZ_PATHNAME) <= 0)
if (envfind ("WCSDIR", Memc[dir], SZ_PATHNAME) <= 0)
if (envfind ("uparm", Memc[dir], SZ_PATHNAME) <= 0)
call strcpy ("tmp$", Memc[dir], SZ_PATHNAME)
if (envfind ("stdimage", Memc[device], SZ_FNAME) <= 0)
call strcpy ("display", Memc[device], SZ_FNAME)
# Get the WCS file filename.
call sprintf (Memc[fname], SZ_PATHNAME, "%s%s_%d.wcs")
call pargstr (Memc[dir])
if (strncmp (Memc[device], "imt", 3) == 0)
call pargstr ("imtool")
else
call pargstr (Memc[device])
call pargi (frame)
if (sz_image > 0)
image[1] = EOS
if (sz_title > 0)
title[1] = EOS
# Get the saved WCS.
iferr (fd = open (Memc[fname], READ_ONLY, TEXT_FILE))
fd = NULL
}
# Decode the WCS from the WCS text.
if (fd != NULL) {
image[1] = EOS
title[1] = EOS
if (fscan (fd) != EOF) {
# Decode "image - title".
if (sz_image > 0)
call gargwrd (image, sz_image)
if (sz_title > 0) {
call gargwrd (title, sz_title)
repeat {
call gargc (ch)
} until (!IS_WHITE(ch))
title[1] = ch
call gargstr (title[2], sz_title - 1)
}
# Decode the WCS information.
if (fscan (fd) != EOF) {
call gargr (a)
call gargr (b)
call gargr (c)
call gargr (d)
call gargr (tx)
call gargr (ty)
call gargr (z1)
call gargr (z2)
call gargi (zt)
if (nscan() == 9)
wcs_status = OK
if (iis_version > 0) {
if (fscan (fd) != EOF) {
call gargstr (iis_region, SZ_FNAME)
call gargr (iis_sx)
call gargr (iis_sy)
call gargi (iis_snx)
call gargi (iis_sny)
call gargi (iis_dx)
call gargi (iis_dy)
call gargi (iis_dnx)
call gargi (iis_dny)
}
if (nscan() == 9) {
if (fscan (fd) != EOF)
call gargstr (iis_objref, SZ_FNAME)
if (nscan() == 1)
iis_valid = YES
} else
iis_valid = NO
} else {
if (nscan() != 9) {
# Set up the unitary transformation if we
# cannot retrieve the real one.
a = 1.0
b = 0.0
c = 0.0
d = 1.0
tx = 1.0
ty = 1.0
wcs_status = ERR
}
}
}
}
}
if (fd != NULL)
call close (fd)
call sfree (sp)
return (wcs_status)
end
|