aboutsummaryrefslogtreecommitdiff
path: root/noao/imred/src/fibers/listonly.cl
blob: ac2158925e82cef80294a7a2b6f1bd2f22c24658 (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
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
# LISTONLY -- List processing to be done.
#
# This follows pretty much the same logic as the full procedure but doesn't
# do anything but list the operations.

procedure listonly (objects, apidtable, apref, flat, throughput, arcs1, arcs2,
	scattered, dispcor, skysubtract, redo, update)

string	objects = ""		{prompt="List of object spectra"}
file	apidtable = ""		{prompt="Aperture ID table"}
file	apref = ""		{prompt="Aperture reference spectrum"}
file	flat = ""		{prompt="Flat field spectrum"}
file	throughput = ""		{prompt="Throughput file or image"}
string	arcs1 = ""		{prompt="List of arc spectra"}
string	arcs2 = ""		{prompt="List of shift arc spectra"}

bool	scattered		{prompt="Subtract scattered light?"}
bool	dispcor			{prompt="Dispersion correct spectra?"}
bool	skysubtract		{prompt="Subtract sky?"}
bool	redo = no		{prompt="Redo operations if previously done?"}
bool	update = yes		{prompt="Update spectra if cal data changes?"}

struct	*fd1
struct	*fd2

begin
	string	imtype, mstype, extn
	string	spec, arcref1, arcref2
	string	specms, arcref1ms, arcref2ms, response
	string	objs, temp, done, str
	bool	reextract, newaps, newresp, newdisp, scat, extract, disp, sky
	int	i, j, n, dc

	imtype = "." // envget ("imtype")
	i = stridx (",", imtype)
	if (i > 0)
	    imtype = substr (imtype, 1, i-1)
	mstype = ".ms" // imtype
	n = strlen (imtype)

	objs = mktemp ("tmp$iraf")
	temp = mktemp ("tmp$iraf")
	done = mktemp ("tmp$iraf")

	if (apidtable != "") {
	    j = strlen (apidtable)
	    for (i=1; i<=j && substr(apidtable,i,i)==" "; i+=1);
	    apidtable = substr (apidtable, i, j)
	}
	i = strlen (apidtable)
	if (i == 0)
	    extn = ".ms"
	else {
	    extn = apidtable
	    while (yes) {
		i = stridx ("/$]", extn)
		if (i == 0)
		    break
		j = strlen (extn)
		extn = substr (extn, i+1, j)
	    }
	    extn = extn // ".ms"
	}

	newaps = no
	newresp = no
	newdisp = no

	i = strlen (apref)
	if (i > n && substr (apref, i-n+1, i) == imtype)
	    apref = substr (apref, 1, i-n)

	reextract = redo
	if (reextract || !access (database // "/ap" // apref // extn)) {
	    print ("Set reference aperture for ", apref)
	    newaps = yes
	}

	i = strlen (flat)
	if (i > n && substr (flat, i-n+1, i) == imtype)
	    flat = substr (flat, 1, i-n)
	if (flat != "") {
	    scat = no
	    if (scattered) {
		if (redo && access (flat//"noscat"//imtype))
		    hselect (flat//"noscat", "apscatte", yes) | scan (str)
		else
		    hselect (flat, "apscatte", yes) | scan (str)
		if (nscan() == 0)
		    scat = yes
	    }
	    if (scat)
		print ("Subtract scattered light from ", flat)
	}

	spec = throughput
	i = strlen (spec)
	if (i > n && substr (spec, i-n+1, i) == imtype)
	    spec = substr (spec, 1, i-n)
	if (spec != "") {
	    scat = no
	    if (scattered) {
		if (redo && access (flat//"noscat"//imtype))
		    hselect (flat//"noscat", "apscatte", yes) | scan (str)
		else
		    hselect (flat, "apscatte", yes) | scan (str)
		if (nscan() == 0)
		    scat = yes
	    }
	    if (scat)
		print ("Subtract scattered light from ", spec)
	}

	response = ""
	if (flat != "" || spec != "") {
	    if (extn == ".ms")
		response = flat // spec // "norm.ms"
	    else
		response = flat // spec // extn

	    reextract = redo || (update && newaps)
	    if (reextract || !access (response // imtype) || (redo && scat)) {
	        print ("Create response function ", response)
	        newresp = yes
	    }
	}

	if (dispcor) {
	    getspec (arcs1, temp)
	    fd1 = temp
	    if (fscan (fd1, arcref1) == EOF)
		error (1, "No reference arcs")
	    fd1 = ""; delete (temp, verify=no)
	    arcref1ms = arcref1 // extn

	    getspec (arcs2, temp)
	    fd1 = temp
	    if (fscan (fd1, arcref2) == EOF)
		arcref2 = ""
	    fd1 = ""; delete (temp, verify=no)
	    arcref2ms = arcref2 // extn

	    reextract = redo || (update && newaps)
	    if (reextract || !access (arcref1ms//imtype)) {
	        print ("Extract arc reference image ", arcref1)
	        print ("Determine dispersion solution for ", arcref1)
	        newdisp = yes
	    } else {
	        hselect (arcref1ms, "dclog1", yes, > temp)
	        fd1 = temp
		dc = -1
	        i = fscan (fd1, dc)
	        fd1 = ""; delete (temp, verify=no)
	        if (i < 1) {
	            print ("Determine dispersion solution for ", arcref1)
	            newdisp = yes
	        }
	    }
	    print (arcref1, > done)

	    if (arcref2 != "") {
	        if (reextract || !access (arcref2ms//imtype) || newdisp) {
		    print ("Extract shift arc reference image ", arcref2)
	            print ("Determine dispersion solution for ", arcref2)
		} else {
		    hselect (arcref2ms, "dclog1", yes, > temp)
		    fd1 = temp
		    dc = -1
		    i = fscan (fd1, dc)
		    fd1 = ""; delete (temp, verify=no)
		    if (i < 1)
	                print ("Determine dispersion solution for ", arcref2)
		}
	    }
	    print (arcref2, >> done)
	}

	reextract = redo || (update && (newaps || newresp || newdisp))
	getspec (objects, objs)
	fd1 = objs
	while (fscan (fd1, spec) != EOF) {
	    if (access (done)) {
	        fd2 = done
	        while (fscan (fd2, specms) != EOF)
		    if (spec == specms)
		        break
	        if (spec == specms)
		    next
	        fd2 = ""
	    }

	    specms = spec // mstype

	    scat = no
	    extract = no
	    disp = no
	    sky = no
	    if (scattered) {
		if (redo && access (spec//"noscat"//imtype))
		    hselect (spec//"noscat", "apscatte", yes) | scan (str)
		else
		    hselect (spec, "apscatte", yes) | scan (str)
		if (nscan() == 0)
		    scat = yes
	    }
	    if (reextract || !access (specms) || (redo && scat))
		extract = yes
	    else {
		hselect (specms, "dclog1", yes) | scan (str)
		if (nscan() == 0)
		    disp = yes
		else
		    extract = update && newdisp
		hselect (specms, "skysub", yes) | scan (str)
		if (nscan() == 0)
		    sky = skysubtract
	    }
		
	    if (extract) {
		disp = dispcor
		sky = skysubtract
	    }
		    
	    if (scat)
		print ("Subtract scattered light from ", spec)
	    if (extract)
		print ("Extract object spectrum ", spec)
	    if (disp)
	        print ("Dispersion correct ", spec)
	    if (sky)
		print ("Sky subtract ", spec)
	}
	fd1 = ""; delete (objs, verify=no)

	if (access (done))
	    delete (done, verify=no)
end