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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
|
include <imhdr.h>
include "rvpackage.h"
include "rvflags.h"
include "rvkeywords.h"
include "rvsample.h"
include "rvcont.h"
# RV_WRITE - Write results to logfile and/or header.
procedure rv_write (rv, record)
pointer rv #I RV struct pointer
int record #I Record number being written
pointer sp, fd, tasknm, buf
begin
fd = RV_TXFD(rv)
call smark (sp)
call salloc (buf, SZ_LINE, TY_CHAR)
call salloc (tasknm, SZ_FNAME, TY_CHAR)
# Update the image header if set
if (RV_IMUPDATE(rv) == YES)
call rv_imupdate (rv)
# write long explanatory header
if (record <= 0) {
call rv_param (rv, fd, "fxcor")
call rv_tempcodes (rv, fd)
call rv_prdeltav (rv, fd)
call fprintf (fd, "# \n")
call rv_hdr (rv, fd)
}
# Update dispersion and the sample regions if they were modified.
if (SR_MODIFY(RV_OSAMPLE(rv)) == YES) {
call rv_make_range_string (RV_OSAMPLE(rv), Memc[buf])
call rv_sparam (RV_TXFD(rv), "osample", Memc[buf], "", "")
SR_MODIFY(RV_OSAMPLE(rv)) = NO
}
if (SR_MODIFY(RV_RSAMPLE(rv)) == YES) {
call rv_make_range_string (RV_RSAMPLE(rv), Memc[buf])
call rv_sparam (RV_TXFD(rv), "rsample", Memc[buf], "", "")
SR_MODIFY(RV_RSAMPLE(rv)) = NO
}
if (RV_VERBOSE(rv) == OF_SHORT || RV_VERBOSE(rv) == OF_STXTONLY)
call rv_write_short (rv, fd)
else
call rv_write_long (rv, fd)
call sfree (sp)
end
# Define the parameter keyword strings in Km/s units.
define RV_NSTR1S "#N OBJECT%13tIMAGE%24tREF%29tHJD%40tAP%44tSHIFT%53tFWHM%62tVHELIO%72tVERR\n"
define RV_USTR1S "#U name%13timage%29tdays%44tpixel%53t %62tkm/s%72tkm/s\n"
define RV_WSTR1S "%-11.11s%13t%-10.10s%24t%.2s%29t%-10.5f%40t%-3d%44t%-7.3f%53t%-7.2f%62t%-9.4f%72t%-7.3f\n"
define RV_NSTR1V "#N%4tOBJECT%18tIMAGE%28tREF%34tHJD%44tAP%50tCODES%60tSHIFT%68tHGHT%73tFWHM%81tTDR%88tVOBS%98tVREL%109tVHELIO%120tVERR\n"
define RV_USTR1V "#U%4tname%18timage%34tdays%50tcfr/fun%60tpixel%73t %88tkm/s%98tkm/s%109tkm/s%120tkm/s\n"
define RV_WSTR1V "%-15.15s %-10s %.2s %-11.5f %-3d %-7.7s %-7.3f %-4.2f %-7.2f %-6.2f %-9.4f %-9.4f %-9.4f %-7.3f\n"
# Now define the parameter keyword strings in terms of redshift Z values.
define RV_NSTR1SZ "#N OBJECT%13tIMAGE%24tREF%28tHJD%40tAP%44tSHIFT%53tFWHM%62tZHELIO%72tVERR\n"
define RV_USTR1SZ "#U name%13timage%28tdays%44tpixel%53t %62tz%72tkm/s\n"
define RV_WSTR1SZ "%-11.11s%13t%-10.10s%24t%.2s%28t%-10.5f%40t%-3d%44t%-7.3f%53t%-7.2f%62t%-7.6f%72t%-7.3f\n"
define RV_NSTR1VZ "#N%4tOBJECT%18tIMAGE%28tREF%34tHJD%44tAP%50tCODES%60tSHIFT%68tHGHT%73tFWHM%81tTDR%88tZOBS%98tZREL%109tZHELIO%120tVERR\n"
define RV_USTR1VZ "#U%4tname%18timage%34tdays%50tcfr/fun%60tpixel%73t %88tz%98tz%109tz%120tkm/s\n"
define RV_WSTR1VZ "%-15.15s %-10s %.2s %-11.5f %-3d %-7.7s %-7.3f %-4.2f %-7.2f %-6.2f %-7.6f %-7.6f %-7.6f %-7.3f\n"
# RV_WRITELN - Write out a line to the status line.
procedure rv_writeln (rv, fd)
pointer rv #I RV struct pointer
pointer fd #I File descriptor
begin
if (fd == NULL)
return
# Check error conditions
if (RV_ERRCODE(rv) == ERR_FIT) {
call fprintf (fd, "Fit did not converge.\n")
return
}
if (RV_PRINTZ(rv) == ERR) # bad velocity computation
RV_PRINTZ(rv) = NO
# Write the status line output
if ((mod(RV_STATLINE(rv),2) == 0 || RV_NEWXCOR(rv) == YES) &&
RV_DCFLAG(rv) != -1) {
if (RV_PRINTZ(rv) == NO) {
call fprintf (fd,
"HJD=%9.4f FWHM=%.2f Vr=%.3f Vo=%.3f Vh=%.3f +/- %.3f\n")
} else {
call fprintf (fd,
"HJD=%9.4f FWHM=%.2f Zr=%.5f Zo=%.5f Zh=%.5f +/- %.3f\n")
}
if (RV_HJD(rv) > 0.0)
call pargd (mod(RV_HJD(rv),double(10000.0)))
else
call pargr (INDEF)
call pargr (RV_DISP(rv))
if (RV_PRINTZ(rv) == NO) {
call pargr (RV_VREL(rv))
call pargd (RV_VOBS(rv))
call pargd (RV_VCOR(rv))
} else {
if (IS_INDEFD(RV_VREL(rv)))
call pargd (INDEFD)
else
call pargd (RV_VREL(rv)/C)
if (IS_INDEFD(RV_VOBS(rv)))
call pargd (INDEFD)
else
call pargd (RV_VOBS(rv)/C)
if (IS_INDEFD(RV_VCOR(rv)))
call pargd (INDEFD)
else
call pargd (RV_VCOR(rv)/C)
}
call pargd (RV_ERROR(rv))
} else {
call fprintf (fd,
"Shift=%.5g +/- %.3g pixels CCF Height=%.3g FWHM = %.3g")
call pargr (RV_SHIFT(rv))
call pargr (RV_SIGMA(rv))
call pargr (RV_HEIGHT(rv))
call pargr (RV_FWHM(rv))
}
call flush (fd)
RV_ERRCODE(rv) = OK
end
# RV_WRITE_SHORT - Write out a line to the logfile or the screen.
procedure rv_write_short (rv, fd)
pointer rv #I RV struct pointer
pointer fd #I File descriptor
int i, nshifts
real wpc
char tc[3]
data wpc /INDEF/
begin
if (fd == NULL)
return
if (RV_PRINTZ(rv) == ERR) # bad velocity computation
RV_PRINTZ(rv) = NO
if (IS_INDEF(wpc)) # update dispersion
wpc = RV_OWPC(rv)
else if (wpc != RV_OWPC(rv)) {
call rv_prdeltav (rv, fd)
wpc = RV_OWPC(rv)
} else
wpc = RV_OWPC(rv)
if (IS_DBLSTAR(rv) == YES) {
nshifts = DBL_NSHIFTS(rv)
do i = 1, nshifts {
call nam_tempcode (RV_TEMPNUM(rv), tc)
if (RV_PRINTZ(rv) == NO)
call fprintf (fd, RV_WSTR1S)
else
call fprintf (fd, RV_WSTR1SZ)
call pargstr (OBJNAME(rv))
call pargstr (IMAGE(rv))
#call pargi (RV_TEMPCODE(rv))
call pargstr (tc)
if (!IS_INDEF(DBL_VHELIO(rv,i)) && RV_HJD(rv) > 0)
call pargd (mod(RV_HJD(rv),double(10000.0)))
else
call pargr (INDEF)
call pargi (RV_APNUM(rv))
call pargr (DBL_SHIFT(rv,i))
call pargr (DBL_FWHM(rv,i))
if (RV_DCFLAG(rv) != -1) {
if (RV_PRINTZ(rv) == NO)
call pargr (DBL_VHELIO(rv,i))
else {
if (IS_INDEFD(DBL_VHELIO(rv,i)))
call pargd (INDEFD)
else
call pargd (DBL_VHELIO(rv,i)/C)
}
} else
call pargr (INDEFR)
call pargr (DBL_VERR(rv,i))
}
} else {
call nam_tempcode (RV_TEMPNUM(rv), tc)
if (RV_PRINTZ(rv) == NO)
call fprintf (fd, RV_WSTR1S)
else
call fprintf (fd, RV_WSTR1SZ)
call pargstr (OBJNAME(rv))
call pargstr (IMAGE(rv))
#call pargi (RV_TEMPCODE(rv))
call pargstr (tc)
if (!IS_INDEFD(RV_VCOR(rv)) && RV_ERRCODE(rv) == OK &&
RV_HJD(rv) > 0.)
call pargd (mod(RV_HJD(rv),double(10000.0)))
else
call pargr (INDEF)
call pargi (RV_APNUM(rv))
if (RV_ERRCODE(rv) == OK) {
call pargr (RV_SHIFT(rv))
if (!IS_INDEFR(RV_DISP(rv)))
call pargr (RV_DISP(rv))
else
call pargr (RV_FWHM(rv))
if (RV_PRINTZ(rv) == NO)
call pargd (RV_VCOR(rv))
else {
if (IS_INDEFD(RV_VCOR(rv)))
call pargd (INDEFD)
else
call pargd (RV_VCOR(rv)/C)
}
call pargd (RV_ERROR(rv))
} else {
call pargr (INDEF)
call pargr (INDEF)
call pargr (INDEF)
call pargr (INDEF)
}
}
call flush (fd)
end
# RV_WRITE_LONG - Write the verbose output line
procedure rv_write_long (rv, fd)
pointer rv #I RV struct pointer
int fd #I File descriptor
pointer sp, cp
int i, nshifts
double vrel, rv_shift2vel()
real wpc
char tc[3]
data wpc /INDEF/
begin
if (fd == NULL)
return
if (RV_PRINTZ(rv) == ERR) # bad velocity computation
RV_PRINTZ(rv) = NO
call smark (sp)
call salloc (cp, SZ_FNAME, TY_CHAR)
# First encode some stuff for output
call rv_codes (rv, Memc[cp], SZ_FNAME)
if (IS_INDEF(wpc)) # update dispersion
wpc = RV_OWPC(rv)
else if (wpc != RV_OWPC(rv)) {
call rv_prdeltav (rv, fd)
wpc = RV_OWPC(rv)
} else
wpc = RV_OWPC(rv)
if (IS_DBLSTAR(rv) == YES) {
nshifts = DBL_NSHIFTS(rv)
do i = 1, nshifts {
call nam_tempcode (RV_TEMPNUM(rv), tc)
if (RV_PRINTZ(rv) == NO)
call fprintf (fd, RV_WSTR1V)
else
call fprintf (fd, RV_WSTR1VZ)
call pargstr (OBJNAME(rv))
call pargstr (IMAGE(rv))
call pargstr (tc)
if (!IS_INDEF(DBL_VHELIO(rv,i)) && RV_HJD(rv) > 0.0)
call pargd (mod(RV_HJD(rv),double(10000.0)))
else
call pargr (INDEF)
call pargi (RV_APNUM(rv))
call pargstr (Memc[cp])
call pargr (DBL_SHIFT(rv,i))
call pargr (DBL_HEIGHT(rv,i))
call pargr (DBL_FWHM(rv,i))
call pargr (DBL_R(rv,i))
if (RV_DCFLAG(rv) != -1) {
if (RV_PRINTZ(rv) == NO) {
call pargr (DBL_VOBS(rv,i))
call pargd (rv_shift2vel(rv,DBL_SHIFT(rv,i)))
call pargr (DBL_VHELIO(rv,i))
} else {
if (IS_INDEFD(DBL_VOBS(rv,i)))
call pargd (INDEFD)
else
call pargd (DBL_VOBS(rv,i)/C)
vrel = rv_shift2vel (rv,DBL_SHIFT(rv,i)) / C
if (IS_INDEFD(vrel))
call pargd (INDEFD)
else
call pargd (vrel)
if (IS_INDEFD(DBL_VHELIO(rv,i)))
call pargd (INDEFD)
else
call pargd (DBL_VHELIO(rv,i)/C)
}
} else {
call pargr (INDEFR)
call pargr (INDEFR)
call pargr (INDEFR)
}
call pargr (DBL_VERR(rv,i))
}
} else {
call nam_tempcode (RV_TEMPNUM(rv), tc)
if (RV_PRINTZ(rv) == NO)
call fprintf (fd, RV_WSTR1V)
else
call fprintf (fd, RV_WSTR1VZ)
call pargstr (OBJNAME(rv))
call pargstr (IMAGE(rv))
#call pargi (RV_TEMPCODE(rv))
call pargstr (tc)
if (!IS_INDEFD(RV_VCOR(rv)) && RV_ERRCODE(rv) == OK &&
RV_HJD(rv) > 0.0)
call pargd (mod(RV_HJD(rv),double(10000.0)))
else
call pargr (INDEF)
call pargi (RV_APNUM(rv))
call pargstr (Memc[cp])
if (RV_ERRCODE(rv) == OK) {
call pargr (RV_SHIFT(rv))
call pargr (RV_HEIGHT(rv))
if (!IS_INDEFR(RV_DISP(rv)))
call pargr (RV_DISP(rv))
else
call pargr (RV_FWHM(rv))
call pargr (RV_R(rv))
if (RV_PRINTZ(rv) == NO) {
call pargd (RV_VOBS(rv))
call pargr (RV_VREL(rv))
call pargd (RV_VCOR(rv))
} else {
if (IS_INDEFD(RV_VOBS(rv)))
call pargd (INDEFD)
else
call pargd (RV_VOBS(rv)/C)
if (IS_INDEFD(RV_VREL(rv)))
call pargd (INDEFD)
else
call pargd (RV_VREL(rv)/C)
if (IS_INDEFD(RV_VCOR(rv)))
call pargd (INDEFD)
else
call pargd (RV_VCOR(rv)/C)
}
call pargd (RV_ERROR(rv))
} else {
call pargr (INDEF)
call pargr (INDEF)
call pargr (INDEF)
call pargr (INDEF)
call pargd (INDEFD)
call pargr (INDEF)
call pargd (INDEFD)
call pargd (INDEFD)
}
}
call flush (fd)
call sfree (sp)
end
# RV_SHORT_HDR - Write out a line to the logfile or the screen.
procedure rv_short_hdr (rv, fd)
pointer rv #I RV struct pointer
pointer fd #I File descriptor
begin
if (fd == NULL)
return
if (RV_PRINTZ(rv) == ERR) # bad velocity computation
RV_PRINTZ(rv) = NO
if (RV_PRINTZ(rv) == NO) {
call fprintf (fd, RV_NSTR1S)
call fprintf (fd, RV_USTR1S)
} else {
call fprintf (fd, RV_NSTR1SZ)
call fprintf (fd, RV_USTR1SZ)
}
call fprintf (fd, "# \n")
call flush (fd)
end
# RV_HDR - Procedure to write the banner for the RVXCOR task.
procedure rv_hdr (rv, fd)
pointer rv #I RV struct pointer
int fd #I File descriptor
begin
if (fd == NULL)
return
if (RV_PRINTZ(rv) == ERR) # bad velocity computation
RV_PRINTZ(rv) = NO
call flush (fd)
if (RV_VERBOSE(rv) == OF_SHORT || RV_VERBOSE(rv) == OF_STXTONLY) {
call rv_short_hdr (rv, fd) # write short header
return
}
if (RV_PRINTZ(rv) == NO) {
call fprintf (fd, RV_NSTR1V)
call fprintf (fd, RV_USTR1V)
} else {
call fprintf (fd, RV_NSTR1VZ)
call fprintf (fd, RV_USTR1VZ)
}
call fprintf (fd, "#\n")
call flush (fd)
end
# RV_CODES - Encode certain parameters into a string for output
procedure rv_codes (rv, out, maxch)
pointer rv #I RV struct pointer
char out[maxch] #O Output code string
int maxch
pointer sp, func
begin
call smark (sp)
call salloc (func, SZ_FNAME, TY_CHAR)
call nam_fitfunc (rv, Memc[func])
call sprintf (out, maxch, "%c%c%c/%-3.3s")
switch (RV_CONTINUUM(rv)) {
case OBJ_ONLY:
call pargi ('O')
case TEMP_ONLY:
call pargi ('T')
case BOTH:
call pargi ('B')
case NONE:
call pargi ('N')
}
switch (RV_FILTER(rv)) {
case OBJ_ONLY:
call pargi ('O')
case TEMP_ONLY:
call pargi ('T')
case BOTH:
call pargi ('B')
case NONE:
call pargi ('N')
}
switch (RV_REBIN(rv)) {
case RB_OBJ:
call pargi ('O')
case RB_TEMP:
call pargi ('T')
case RB_SMALL:
call pargi ('S')
case RB_BIG:
call pargi ('L')
}
call pargstr (Memc[func])
call sfree (sp)
end
# RV_TEMPCODES - Output the template codes and information
procedure rv_tempcodes (rv, fd)
pointer rv #I RV struct pointer
int fd #i Output file descriptor
pointer sp, buf, im, title
int i, imtrgetim(), strlen()
char tc[3]
begin
if (fd == NULL)
return
call smark (sp)
call salloc (buf, 4*SZ_LINE, TY_CHAR)
call salloc (im, SZ_LINE, TY_CHAR)
call salloc (title, SZ_LINE, TY_CHAR)
call fprintf (fd, "# \n")
do i = 1, RV_NTEMPS(rv) {
if (imtrgetim(RV_TEMPLATES(rv), i, Memc[im], SZ_FNAME) != EOF)
call rv_imtitle (Memc[im], Memc[title], SZ_FNAME)
# Truncate the leading path if needed.
if (strlen(Memc[im]) > 30)
call rv_strip_path (Memc[im], 30)
call nam_tempcode (i, tc)
call sprintf (Memc[buf], SZ_LINE,
"#T %s '%.2s' -- %s = '%.40s'%78t\*\n#%21t%s = '%.30s'%64t%s = %.2f")
call pargstr ("Template")
call pargstr (tc)
call pargstr ("Object")
call pargstr (Memc[title])
call pargstr ("Image ")
call pargstr (Memc[im])
call pargstr ("Vhelio")
call pargr (TEMPVEL(rv,i))
call fprintf (fd, "%s\n")
call pargstr (Memc[buf])
}
call fprintf (fd, "# \n")
call sfree (sp)
end
# RV_PRDELTAV - Output the velocity per pixel dispersion of the image.
procedure rv_prdeltav (rv, fd)
pointer rv #I RV struct pointer
int fd #I Output file descriptor
begin
if (fd == NULL)
return
call fprintf (fd, "# Velocity Dispersion = %-.2f Km/sec/pixel ")
call pargr (RV_DELTAV(rv))
call fprintf (fd, "Rebinned WPC = %-.6g\n")
if (RV_DCFLAG(rv) != -1)
call pargr (RV_OWPC(rv))
else
call pargr (INDEFR)
call flush (fd)
end
# RV_IMUPDATE - Update the image header with requested information
procedure rv_imupdate (rv)
pointer rv #I RV struct pointer
pointer im, immap()
int imaccf()
errchk immap, imaccf, imaddr
begin
im = immap (IMAGE(rv), READ_WRITE, 0)
if (IM_LEN(im,2) > 1 && IM_NDIM(im) > 1) {
call rv_err_comment (rv,
"WARNING: Cannot currently update a two-dimensional image.",
"")
} else {
# Write observed & corrected velocity to image header
iferr {
if (imaccf(im,KW_HJD(rv)) == NO)
call imaddd (im, KW_HJD(rv), RV_HJD(rv))
else
call imputd (im, KW_HJD(rv), RV_HJD(rv))
if (imaccf(im,KW_MJD_OBS(rv)) == NO)
call imaddd (im, KW_MJD_OBS(rv), RV_MJD_OBS(rv))
else
call imputd (im, KW_MJD_OBS(rv), RV_MJD_OBS(rv))
if (imaccf(im,KW_VOBS(rv)) == NO)
call imaddd (im, KW_VOBS(rv), RV_VOBS(rv))
else
call imputd (im, KW_VOBS(rv), RV_VOBS(rv))
if (imaccf(im,KW_VHELIO(rv)) == NO)
call imaddd (im, KW_VHELIO(rv), RV_VCOR(rv))
else
call imputd (im, KW_VHELIO(rv), RV_VCOR(rv))
} then
call rv_err_comment (rv,
" ERROR: Error updating image header.", "")
}
call imunmap (im)
end
# RV_STRIP_PATH - Truncate a string to the rightmost number of characters
# specified.
procedure rv_strip_path (str, maxch)
char str[ARB] #I Input string
int maxch #I Maxchars
int ip, strlen()
begin
ip = max (1, strlen (str) - maxch + 1)
call amovc (str[ip], str, maxch)
str[31] = '\0'
end
|