This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
statelist.cl
279 lines (263 loc) · 10.2 KB
/
statelist.cl
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
# STATELIST: 04AUG98 KMM expects IRAF 2.11Export or later
# STATELIST: 02JAN95 KMM generate lists of on or off frames for input images
# generated from the following protocols
# all_on: + + + + + order=1
# pair: +- +- +- order=2
# triad: +-+ +-+ order=3
# quad: +--+ +--+ order=4
# alt-quad: -++- -++- order=5
# alt-triad: -++ -++ order=6
# STATELIST: 18FEB95 KMM Shorten rowlength of final table so longer pathnames
# will work (was overflowing linelength allowed for
# "fields"/"type".
# Lines with ## contain an alternative, more aggressive,
# solution which holds down the row lengths within the
# intermediate tables.
# STATELIST: 28JUL98 KMM add global image extension
# eliminate STSDAS table package dependency
# STATELIST: 03AUG98 KMM add alternative quad processing -++- and
# alternative triad processing -++
# enable multiple images per state, e.g.:
# multiple=2 alt_triad
# --++++ --++++ --++++
# STATELIST: 04AUG98 KMM add new variable output "format"
# when state = "obj|on|off|sky"
# if format = 1name on|off
# if format = group on|off, group#
# else on|off, group#, list#
# when state = "op"
# if format = 1name on, nearest off
# if format = 2name on, nearest 2 offs
# if format = group on, nearest 2 offs, group#
# else on, nearest 2 offs, group#, list#
procedure statelist (input)
string input {prompt="Input raw images"}
int order {2, min=1, max=6,
prompt="Pattern # 1:++ 2:+- 3:+-+ 4:+--+ 5:-++- 6:-++ ?"}
int multiple {1, prompt="Number of frames at each pattern state?"}
string state {"on",prompt="Image state selected: on|obj|off|op|sky",
enum="on|obj|off|op|sky"}
string format {"full",prompt="Output format: 1name|2name|group|full ?",
enum="1name|2name|group|full"}
struct *inlist,*onlist,*offlist
begin
int nin, stat, pos1b, pos1e, pos2b, pos2e,
nex, nim, non, ntot, noff, noff0, noff1, noff2,
num, ngp, ngp0, ngp1, ngp2
real rnorm, rmean, rmedian, rmode, objdiffstat, objonstat, objoffstat,
skyonstat, skyoffstat, skydiffstat
string in,in1,in2,out,iroot,oroot,uniq,img,sname,sout,sjunk
file infile, outfile, onfile, offfile, opfile, tmp1
string gimextn, imextn, imname, imroot
string on, off, off0, off1, off2
struct line = ""
# Assign positional parameters to local variables
in = input
num = multiple
# get IRAF global image extension
show("imtype") | translit ("",","," ",delete-) | scan (gimextn)
nex = strlen(gimextn)
infile = mktemp ("tmp$stl")
outfile = mktemp ("tmp$stl")
onfile = mktemp ("tmp$stl")
offfile = mktemp ("tmp$stl")
tmp1 = mktemp ("tmp$stl")
# check whether input stuff exists
print (in) | translit ("", "@:", " ") | scan(in1,in2)
if ((stridx("@",in) == 1) && (! access(in1))) { # check input @file
print ("Input file ",in1," does not exist!")
goto skip
}
sections (in,option="nolist")
if (sections.nimages == 0) { # check input images
print ("Input images in file ",in, " do not exist!")
goto skip
}
# Expand input file name list
# option="root" truncates lines beyond ".imh" including section info
sections (in,option="root",> tmp1)
# generate lists of on and off fields
inlist = tmp1
for (nin = 1; (fscan(inlist,imname) != EOF); nin +=1) {
print(imname," ",nin,>> infile)
}
delete (tmp1, verify-,>& "dev$null")
count(infile) | scan(ntot)
inlist = infile
while(fscan(inlist,imname,nin) != EOF) {
ngp = int((nin+num-1)/num)
switch (order) {
case 1: { # all_on: + + + + +
print(imname," ",nin,ngp,>> onfile)
print(imname," ",nin,ngp,>> offfile)
}
case 2: { # pair: +- +- +-
if (ngp % 2 == 1)
print(imname," ",nin,ngp,>> onfile)
else
print(imname," ",nin,ngp,>> offfile)
}
case 3: { # triad: +-+ +-+
if (ngp % 3 != 2)
print(imname," ",nin,ngp,>> onfile)
else
print(imname," ",nin,ngp,>> offfile)
}
case 4: { # quad: +--+ +--+
if (ngp % 4 <= 1)
print(imname," ",nin,ngp,>> onfile)
else
print(imname," ",nin,ngp,>> offfile)
}
case 5: { # alt-quad: -++- -++-
if (ngp % 4 > 1)
print(imname," ",nin,ngp,>> onfile)
else
print(imname," ",nin,ngp,>> offfile)
}
case 6: { # alt-triad: -++ -++
if (ngp % 3 != 1)
print(imname," ",nin,ngp,>> onfile)
else
print(imname," ",nin,ngp,>> offfile)
}
}
}
count(onfile) | scan(non)
count(offfile) | scan(noff)
off1 = ""; off2 = ""
offlist = offfile
onlist = onfile
if (state == "op") {
for (non = 1; (fscan(onlist,imname,nin) != EOF); non +=1) {
ngp = int((non+num-1)/num)
switch (order) {
case 1: { # all_on: + + + + +
print (imname," ",imname," ",imname," ",nin,ngp,>> outfile)
}
case 2: { # pair: +- +- +-
if (non == 1) {
stat = fscan(offlist,off1)
stat = fscan(offlist,off2)
} else if (non > 2) {
stat = fscan(offlist,off0)
if (stat >= 1) {
off1 = off2
off2 = off0
}
}
if (stat >= 1)
print(imname," ",off1," ",off2," ",nin,ngp,>> outfile)
else
print(imname," ",off2," ",off1," ",nin,ngp,>> outfile)
}
case 3: { # triad: +-+ +-+
if (non == 1) {
stat = fscan(offlist,off1)
stat = fscan(offlist,off2)
print(imname," ",off1," ",off2," ",nin,ngp,>> outfile)
next
}
if (non > 3 && non % 2 == 0) {
stat = fscan(offlist,off0)
if (stat == 1) {
off1 = off2
off2 = off0
}
}
if (non % 2 == 0 && stat >= 1)
print(imname," ",off1," ",off2," ",nin,ngp,>> outfile)
else
print(imname," ",off2," ",off1," ",nin,ngp,>> outfile)
}
case 4: { # quad: +--+ +--+
if (non == 1) {
stat = fscan(offlist,off2)
stat = fscan(offlist,off1)
} else if (non == 2) {
stat = fscan(offlist,off2)
} if (non > 2 && non % 2 == 0) {
stat = fscan(offlist,off0)
if (stat >= 1) {
off1 = off0
stat = fscan(offlist,off0)
if (stat >= 1) {
off2 = off0
}
}
}
if (non % 2 == 0 || stat != 1)
print(imname," ",off1," ",off2," ",nin,ngp,>> outfile)
else
print(imname," ",off2," ",off1," ",nin,ngp,>> outfile)
}
case 5: { # alt-quad: -++- -++-
if (non == 1) {
stat = fscan(offlist,off2)
stat = fscan(offlist,off1)
} else if (non == 2) {
stat = fscan(offlist,off2)
} if (non > 2 && non % 2 == 0) {
stat = fscan(offlist,off0)
if (stat >= 1) {
off1 = off0
stat = fscan(offlist,off0)
if (stat >= 1) {
off2 = off0
}
}
}
if (non % 2 == 0 || stat < 1)
print(imname," ",off1," ",off2," ",nin,ngp,>> outfile)
else
print(imname," ",off2," ",off1," ",nin,ngp,>> outfile)
}
case 6: { # alt-triad: -++ -++
if (non == 1) {
stat = fscan(offlist,off1)
stat = fscan(offlist,off2)
print(imname," ",off1," ",off2," ",nin,ngp,>> outfile)
next
}
if (non > 2 && non % 2 == 0) {
stat = fscan(offlist,off0)
if (stat >= 1) {
off1 = off2
off2 = off0
}
}
if (non % 2 == 0 && stat == 0)
print(imname," ",off1," ",off2," ",nin,ngp,>> outfile)
else
print(imname," ",off2," ",off1," ",nin,ngp,>> outfile)
}
}
}
if (format == "1name" )
fields(outfile,"1,2",lines="1-",print-)
else if (format == "2name")
fields(outfile,"1,2,3",lines="1-",print-)
else if (format == "group")
fields(outfile,"1,2,3,5",lines="1-",print-)
else
fields(outfile,"1,2,3,5,4",lines="1-",print-)
} else if (state == "off" || state == "sky") {
if (format == "1name")
fields (offfile,"1",lines="1-",print-)
else if (format == "group")
fields (offfile,"1,3",lines="1-",print-)
else
fields (offfile,"1,3,2",lines="1-",print-)
} else {
if (format == "1name")
fields (onfile,"1",lines="1-",print-)
else if (format == "group")
fields (onfile,"1,3",lines="1-",print-)
else
fields (onfile,"1,3,2",lines="1-",print-)
}
skip:
# Finish up
onlist = ""; offlist = ""; inlist = ""
delete (onfile//","//offfile//","//infile//","//tmp1, verify-,>& "dev$null")
end