aboutsummaryrefslogtreecommitdiff
path: root/noao/twodspec/apextract/apicset.x
blob: b837a991e523ddb20d6fc3487bc0e10c2bcaf8f5 (plain) (blame)
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
include	<imhdr.h>
include	"apertures.h"

# AP_ICSET -- Set the background fitting ICFIT structure for an aperture.
# If the input template aperture is NULL then the output background fitting
# ICFIT pointer is initialized otherwise a copy from the input template
# aperture is made.

procedure ap_icset (apin, apout, imlen)

pointer	apin		# Input template aperture pointer
pointer	apout		# Output aperture pointer
int	imlen		# Image length along aperture axis

int	i
real	x, x1, x2
pointer	ic, sp, str

int	apgeti(), ctor()
real	apgetr()

begin
	call smark (sp)
	call salloc (str, SZ_LINE, TY_CHAR)

	if (AP_IC(apout) == NULL)
	    call ic_open (AP_IC(apout))
	ic = AP_IC(apout)

	if (apin == NULL) {
	    call apgstr ("b_function", Memc[str], SZ_LINE)
	    call ic_pstr (ic, "function", Memc[str])
	    call ic_puti (ic, "order", apgeti ("b_order"))
	    call apgstr ("b_sample", Memc[str], SZ_LINE)
	    for (i=str; Memc[i]==' '; i=i+1)
		;
	    if (Memc[i] == EOS)
		call strcpy ("*", Memc[str], SZ_LINE)
	    call ic_pstr (ic, "sample", Memc[str])
	    call ic_puti (ic, "naverage", apgeti ("b_naverage"))
	    call ic_puti (ic, "niterate", apgeti ("b_niterate"))
	    call ic_putr (ic, "low", apgetr ("b_low_reject"))
	    call ic_putr (ic, "high", apgetr ("b_high_reject"))
	    call ic_putr (ic, "grow", apgetr ("b_grow"))
	    if (AP_AXIS(apout) == 1)
		    call ic_pstr (ic, "xlabel", "Column")
		else
		    call ic_pstr (ic, "xlabel", "Line")
	} else {
	    if (AP_IC(apin) == NULL) {
		call ic_closer (AP_IC(apout))
		AP_IC(apout) = NULL
		ic = NULL
	    } else if (AP_IC(apin) != ic)
	        call ic_copy (AP_IC(apin), ic)
	}

	# Set the background limits
	if (ic != NULL) {
	    i = AP_AXIS(apout)
	    x1 = AP_LOW(apout, i)
	    x2 = AP_HIGH(apout, i)

	    call ic_gstr (ic, "sample", Memc[str], SZ_LINE)
	    for (i=str; Memc[i]!=EOS; i=i+1)
		if (Memc[i] == ':')
		    Memc[i] = ','
	    for (i=1; Memc[str+i-1]!=EOS; i=i+1) {
		if (Memc[str+i-1] == '*') {
		    x1 = min (x1, real(-imlen))
		    x2 = max (x2, real(imlen))
		} else if (ctor (Memc[str], i, x) > 0) {
		    x1 = min (x1, x)
		    x2 = max (x2, x)
		    i = i - 1
	        }
	    }

	    call ic_putr (ic, "xmin", x1)
	    call ic_putr (ic, "xmax", x2)
	}

	call sfree (sp)
end