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
|
include <imhdr.h>
include "rvpackage.h"
include "rvflags.h"
include "rvcont.h"
include "rvfilter.h"
# WRITE_CCF - Write the CCF image to disk.
procedure write_ccf (rv)
pointer rv #I RV struct pointer
pointer sp, bp
int imaccess(), access()
int stat, scan()
bool streq()
define err_ 99
define loop_ 98
begin
call smark (sp)
call salloc (bp, SZ_FNAME, TY_CHAR)
if (RV_CCFFILE(rv) == NULL) {
call malloc (RV_CCFFILE(rv), SZ_FNAME, TY_CHAR)
Memc[RV_CCFFILE(rv)] = EOS
}
call gargstr (Memc[bp], SZ_FNAME)
if (Memc[bp] != EOS)
call strcpy (Memc[bp], Memc[RV_CCFFILE(rv)], SZ_FNAME)
else {
loop_ call printf ("Output filename (%s): ")
call pargstr (Memc[RV_CCFFILE(rv)])
call flush (STDOUT)
stat = scan ()
call gargstr (Memc[bp], SZ_FNAME)
if (Memc[bp] != EOS && Memc[bp] != '\n')
call strcpy (Memc[bp], Memc[RV_CCFFILE(rv)], SZ_FNAME)
else if (streq("",Memc[RV_CCFFILE(rv)]) ||
streq(" ",Memc[RV_CCFFILE(rv)]))
goto loop_
}
if (RV_CCFTYPE(rv) == OUTPUT_TEXT) {
if (access (Memc[RV_CCFFILE(rv)], 0, 0) == YES) {
call printf ("Warning: File `%s' already exists.\n")
call pargstr (Memc[RV_CCFFILE(rv)])
call flush (STDOUT)
call tsleep (2)
goto loop_
}
call wrt_ccf_text(rv)
} else if (RV_CCFTYPE(rv) == OUTPUT_IMAGE) {
if (imaccess(Memc[RV_CCFFILE(rv)], 0) == YES) {
call printf ("Warning: Image `%s' already exists.\n")
call pargstr (Memc[RV_CCFFILE(rv)])
call flush (STDOUT)
call tsleep (2)
goto loop_
}
call wrt_ccf_image(rv)
}
err_ call sfree (sp)
end
# WRT_CCF_IMAGE - Write the ccf as an output image with appropriate header
# information.
procedure wrt_ccf_image (rv)
pointer rv #I RV struct pointer
pointer sp, x, im, buf, bp
pointer immap(), impl1r()
double rv_shift2vel()
errchk immap, impl1r
define err_ 99
begin
call smark (sp)
call salloc (x, RV_CCFNPTS(rv), TY_REAL)
call salloc (bp, SZ_FNAME, TY_CHAR)
# Open the image
iferr (im = immap(Memc[RV_CCFFILE(rv)], NEW_IMAGE, 2880)) {
call rv_errmsg ("Error opening ccf output image '%s'.")
call pargstr (Memc[RV_CCFFILE(rv)])
goto err_
}
# Set up the image parameters
IM_PIXTYPE(im) = TY_REAL
IM_NDIM(im) = 1
IM_LEN(im,1) = RV_CCFNPTS(rv)
call sprintf (IM_TITLE(im), SZ_IMTITLE, "Correlation Function")
# Now dump the data into the image
buf = impl1r (im)
call amovr (WRKPIXY(rv,1), Memr[buf], RV_CCFNPTS(rv))
# Add image header information
call imastr (im, "object", IMAGE(rv))
call imastr (im, "template", RIMAGE(rv))
call imaddi (im, "npts", RV_CCFNPTS(rv))
if (RV_DCFLAG(rv) != -1) {
call imaddr (im, "crval1",
real(rv_shift2vel(rv,real(-(RV_CCFNPTS(rv)/2)))))
call imaddr (im, "cdelt1", RV_DELTAV(rv))
} else {
call imaddr (im, "crval1", real(-RV_CCFNPTS(rv))/2.)
call imaddr (im, "cdelt1", 1.)
}
call imaddi (im, "crpix1", 1)
call imastr (im, "ctype1", "velocity")
call imastr (im, "cunit1", "km/s")
call nam_filtype (rv, Memc[bp])
call imastr (im, "filtype", Memc[bp])
call imaddi (im, "cuton", RVF_CUTON(rv))
call imaddi (im, "cutoff", RVF_CUTOFF(rv))
call imaddi (im, "fullon", RVF_FULLON(rv))
call imaddi (im, "fulloff", RVF_FULLOFF(rv))
call imunmap (im)
err_ call sfree (sp)
end
# WRT_CCF_TEXT - Write out the ccf to a text file.
procedure wrt_ccf_text (rv)
pointer rv #I RV struct pointer
pointer fd, sp, x
int i, j, npts
pointer open()
double rv_shift2vel()
errchk open
begin
# Open the text file
iferr (fd=open(Memc[RV_CCFFILE(rv)], NEW_FILE, TEXT_FILE)) {
call rv_errmsg ("Error opening ccf output file `%s'.")
call pargstr (Memc[RV_CCFFILE(rv)])
return
}
npts = RV_CCFNPTS(rv)
call smark (sp)
call salloc (x, npts, TY_REAL)
# Sret up X-axis
if (RV_DCFLAG(rv) != -1) {
do i = 1, npts
Memr[x+i-1] = real (rv_shift2vel(rv,WRKPIXX(rv,i)))
} else {
i = - (RV_CCFNPTS(rv) / 2)
do j = 1, npts {
Memr[x+j-1] = real (i)
i = i + 1
}
}
# Write it out
do i = 1, npts {
call fprintf (fd, "%.1f %f\n")
call pargr (Memr[x+i-1])
call pargr (WRKPIXY(rv,i))
}
call flush (fd)
call close (fd)
call sfree (sp)
end
|