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
|
include <error.h>
include <imhdr.h>
include <imset.h>
include "xregister.h"
# RG_XCOLON-- Procedure to process colon commands for setting the cross-
# correlation parameters.
procedure rg_xcolon (gd, xc, imr, im1, im2, db, dformat, tfd, reglist, cmdstr,
newdata, newcross, newcenter)
pointer gd #I pointer to the graphics stream
pointer xc #I pointer to cross-correlation structure
pointer imr #I/O pointer to the reference image
pointer im1 #I/O pointer to the input image
pointer im2 #I/O pointer to the output image
pointer db #I/O pointer to the shifts database file
int dformat #I is the shifts file in database format
int tfd #I/O the transformations file descriptor
pointer reglist #I/O pointer to the regions list
char cmdstr[ARB] #I input command string
int newdata #I/O new input data
int newcross #I/O new cross-correlation function flag
int newcenter #I/O new cross-correlation peak flag
bool streq()
int ncmd, creg, nreg, ival, stat
pointer sp, cmd, str
real rval
int strdic(), open(), nscan(), rg_xstati(), fntopnb()
int rg_xregions(), rg_xmkregions(), strlen()
pointer immap(), dtmap(), rg_xstatp()
real rg_xstatr()
errchk immap(), dtmap(), open(), fntopnb()
begin
call smark (sp)
call salloc (cmd, SZ_LINE, TY_CHAR)
call salloc (str, SZ_LINE, TY_CHAR)
# Get the command.
call sscan (cmdstr)
call gargwrd (Memc[cmd], SZ_LINE)
if (Memc[cmd] == EOS) {
call sfree (sp)
return
}
# Process the command.
ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, XCMDS)
switch (ncmd) {
case XCMD_REFIMAGE:
call gargwrd (Memc[cmd], SZ_LINE)
call rg_xstats (xc, REFIMAGE, Memc[str], SZ_FNAME)
if (Memc[cmd] == EOS || streq (Memc[cmd], Memc[str])) {
call printf ("%s: %s\n")
call pargstr (KY_REFIMAGE)
call pargstr (Memc[str])
} else {
if (imr != NULL) {
call imunmap (imr)
imr = NULL
}
iferr {
imr = immap (Memc[cmd], READ_ONLY, 0)
} then {
call erract (EA_WARN)
imr = immap (Memc[str], READ_ONLY, 0)
} else if (IM_NDIM(imr) > 2 || IM_NDIM(imr) != IM_NDIM(im1)) {
call printf (
"Image has the wrong number of dimensions\n")
call imunmap (imr)
imr = immap (Memc[str], READ_ONLY, 0)
} else {
call rg_xsets (xc, REFIMAGE, Memc[cmd])
newdata = YES; newcross = YES; newcenter = YES
}
}
case XCMD_IMAGE:
call gargwrd (Memc[cmd], SZ_LINE)
call rg_xstats (xc, IMAGE, Memc[str], SZ_FNAME)
if (Memc[cmd] == EOS || streq (Memc[cmd], Memc[str])) {
call printf ("%s: %s\n")
call pargstr (KY_IMAGE)
call pargstr (Memc[str])
} else {
if (im1 != NULL) {
call imunmap (im1)
im1 = NULL
}
iferr {
im1 = immap (Memc[cmd], READ_ONLY, 0)
call imseti (im1, IM_TYBNDRY, BT_NEAREST)
if (IM_NDIM(im1) == 1)
call imseti (im1, IM_NBNDRYPIX, IM_LEN(im1,1))
else
call imseti (im1, IM_NBNDRYPIX,
max (IM_LEN(im1,1), IM_LEN(im1,2)))
} then {
call erract (EA_WARN)
im1 = immap (Memc[str], READ_ONLY, 0)
call imseti (im1, IM_TYBNDRY, BT_NEAREST)
if (IM_NDIM(im1) == 1)
call imseti (im1, IM_NBNDRYPIX, IM_LEN(im1,1))
else
call imseti (im1, IM_NBNDRYPIX,
max (IM_LEN(im1,1), IM_LEN(im1,2)))
} else if (IM_NDIM(im1) > 2 || IM_NDIM(im1) != IM_NDIM(imr)) {
call printf (
"Image has the wrong number of dimensions\n")
call imunmap (im1)
im1 = immap (Memc[str], READ_ONLY, 0)
call imseti (im1, IM_TYBNDRY, BT_NEAREST)
if (IM_NDIM(im1) == 1)
call imseti (im1, IM_NBNDRYPIX, IM_LEN(im1,1))
else
call imseti (im1, IM_NBNDRYPIX,
max (IM_LEN(im1,1), IM_LEN(im1,2)))
} else {
call rg_xsets (xc, IMAGE, Memc[cmd])
newdata = YES; newcross = YES; newcenter = YES
}
}
case XCMD_OUTIMAGE:
call gargwrd (Memc[cmd], SZ_LINE)
call rg_xstats (xc, OUTIMAGE, Memc[str], SZ_FNAME)
if (im2 == NULL || Memc[cmd] == EOS || streq (Memc[cmd],
Memc[str])) {
call printf ("%s: %s\n")
call pargstr (KY_OUTIMAGE)
call pargstr (Memc[str])
} else {
if (im2 != NULL) {
call imunmap (im2)
im2 = NULL
}
iferr {
im2 = immap (Memc[cmd], NEW_COPY, im1)
} then {
call erract (EA_WARN)
im2 = immap (Memc[str], NEW_COPY, im1)
} else {
call rg_xsets (xc, OUTIMAGE, Memc[cmd])
}
}
case XCMD_DATABASE:
call gargwrd (Memc[cmd], SZ_LINE)
call rg_xstats (xc, DATABASE, Memc[str], SZ_FNAME)
if (Memc[cmd] == EOS || streq (Memc[cmd], Memc[str])) {
call printf ("%s: %s\n")
call pargstr (KY_DATABASE)
call pargstr (Memc[str])
} else {
if (db != NULL) {
if (dformat == YES)
call dtunmap (db)
else
call close (db)
db = NULL
}
iferr {
if (dformat == YES)
db = dtmap (Memc[cmd], APPEND)
else
db = open (Memc[cmd], NEW_FILE, TEXT_FILE)
} then {
call erract (EA_WARN)
if (dformat == YES)
db = dtmap (Memc[str], APPEND)
else
db = open (Memc[str], APPEND, TEXT_FILE)
} else {
call rg_xsets (xc, DATABASE, Memc[cmd])
}
}
CASE XCMD_RECORD:
call gargstr (Memc[cmd], SZ_LINE)
if (Memc[cmd] == EOS) {
call rg_xstats (xc, RECORD, Memc[str], SZ_FNAME)
call printf ("%s: %s\n")
call pargstr (KY_RECORD)
call pargstr (Memc[str])
} else
call rg_xsets (xc, RECORD, Memc[cmd])
case XCMD_CREGION:
call gargi (nreg)
creg = rg_xstati (xc, CREGION)
if (nscan() == 1 || (nreg == creg)) {
call printf ("%s: %d/%d")
call pargstr (KY_CREGION)
call pargi (creg)
call pargi (rg_xstati (xc, NREGIONS))
call printf (" [%d:%d,%d:%d]\n")
call pargi (Memi[rg_xstatp (xc,RC1)+creg-1])
call pargi (Memi[rg_xstatp (xc,RC2)+creg-1])
call pargi (Memi[rg_xstatp (xc,RL1)+creg-1])
call pargi (Memi[rg_xstatp (xc,RL2)+creg-1])
} else {
if (nreg < 1 || nreg > rg_xstati (xc,NREGIONS)) {
call printf ("Region %d is out of range\n")
call pargi (nreg)
} else {
call printf (
"Setting current region to %d: [%d:%d,%d:%d]\n")
call pargi (nreg)
call pargi (Memi[rg_xstatp (xc,RC1)+nreg-1])
call pargi (Memi[rg_xstatp (xc,RC2)+nreg-1])
call pargi (Memi[rg_xstatp (xc,RL1)+nreg-1])
call pargi (Memi[rg_xstatp (xc,RL2)+nreg-1])
call rg_xseti (xc, CREGION, nreg)
newdata = YES; newcross = YES; newcenter = YES
}
}
case XCMD_REGIONS:
call gargwrd (Memc[cmd], SZ_LINE)
call rg_xstats (xc, REGIONS, Memc[str], SZ_FNAME)
if (nscan() == 1 || streq (Memc[cmd], Memc[str]) || Memc[cmd] ==
EOS) {
call printf ("%s [string/file]: %s\n")
call pargstr (KY_REGIONS)
call pargstr (Memc[str])
} else {
if (reglist != NULL) {
call fntclsb (reglist)
reglist = NULL
}
iferr (reglist = fntopnb (Memc[cmd], NO))
reglist = NULL
if (rg_xregions (reglist, imr, xc, 1) > 0) {
call rg_xseti (xc, CREGION, 1)
call rg_xsets (xc, REGIONS, Memc[cmd])
newdata = YES; newcross = YES; newcenter = YES
} else {
if (reglist != NULL) {
call fntclsb (reglist)
reglist = NULL
}
iferr (reglist = fntopnb (Memc[str], NO))
reglist = NULL
if (rg_xregions (reglist, imr, xc, 1) > 0)
;
call rg_xsets (xc, REGIONS, Memc[str])
call rg_xseti (xc, CREGION, 1)
}
}
case XCMD_REFFILE:
call gargwrd (Memc[cmd], SZ_LINE)
call rg_xstats (xc, REFFILE, Memc[str], SZ_FNAME)
if (Memc[cmd] == EOS || streq (Memc[cmd], Memc[str])) {
call printf ("%s: %s\n")
call pargstr (KY_REFFILE)
call pargstr (Memc[str])
} else {
if (tfd != NULL) {
call close (tfd)
tfd = NULL
}
iferr {
tfd = open (Memc[cmd], READ_ONLY, TEXT_FILE)
} then {
tfd = NULL
call erract (EA_WARN)
call rg_xsets (xc, REFFILE, "")
call printf ("Coords file is undefined.\n")
} else
call rg_xsets (xc, REFFILE, Memc[cmd])
newdata = YES; newcross = YES; newcenter = YES
}
case XCMD_XLAG:
call gargi (ival)
if (nscan () == 1) {
call printf ("%s = %d\n")
call pargstr (KY_XLAG)
call pargi (rg_xstati (xc, XLAG))
} else {
call rg_xseti (xc, XLAG, ival)
newdata = YES; newcross = YES; newcenter = YES
}
case XCMD_YLAG:
call gargi (ival)
if (nscan() == 1) {
call printf ("%s = %d\n")
call pargstr (KY_YLAG)
call pargi (rg_xstati (xc, YLAG))
} else {
call rg_xseti (xc, YLAG, ival)
newdata = YES; newcross = YES; newcenter = YES
}
case XCMD_DXLAG:
call gargi (ival)
if (nscan() == 1) {
call printf ("%s = %d\n")
call pargstr (KY_DXLAG)
call pargi (rg_xstati (xc, DXLAG))
} else {
call rg_xseti (xc, DXLAG, ival)
}
case XCMD_DYLAG:
call gargi (ival)
if (nscan() == 1) {
call printf ("%s = %d\n")
call pargstr (KY_DYLAG)
call pargi (rg_xstati (xc, DYLAG))
} else {
call rg_xseti (xc, DYLAG, ival)
}
case XCMD_BACKGROUND:
call gargwrd (Memc[cmd], SZ_LINE)
if (Memc[cmd] != EOS)
call strcat (" ", Memc[cmd], SZ_LINE)
call gargwrd (Memc[cmd+strlen(Memc[cmd])], SZ_LINE)
if (Memc[cmd] == EOS) {
call rg_xstats (xc, BSTRING, Memc[str], SZ_FNAME)
call printf ("%s: %s\n")
call pargstr (KY_BACKGROUND)
call pargstr (Memc[str])
} else {
call rg_xsets (xc, BSTRING, Memc[cmd])
newdata = YES; newcross = YES; newcenter = YES
}
case XCMD_BORDER:
call gargi (ival)
if (nscan() == 1) {
call printf ("%s = %d\n")
call pargstr (KY_BORDER)
call pargi (rg_xstati (xc, BORDER))
} else {
call rg_xseti (xc, BORDER, ival)
newdata = YES; newcross = YES; newcenter = YES
}
case XCMD_LOREJECT:
call gargr (rval)
if (nscan() == 1) {
call printf ("%s = %g\n")
call pargstr (KY_LOREJECT)
call pargr (rg_xstatr (xc, LOREJECT))
} else {
call rg_xsetr (xc, LOREJECT, rval)
newdata = YES; newcross = YES; newcenter = YES
}
case XCMD_HIREJECT:
call gargr (rval)
if (nscan() == 1) {
call printf ("%s = %g\n")
call pargstr (KY_HIREJECT)
call pargr (rg_xstatr (xc, HIREJECT))
} else {
call rg_xsetr (xc, HIREJECT, rval)
newdata = YES; newcross = YES; newcenter = YES
}
case XCMD_APODIZE:
call gargr (rval)
if (nscan() == 1) {
call printf ("%s = %g\n")
call pargstr (KY_APODIZE)
call pargr (rg_xstatr (xc, APODIZE))
} else {
call rg_xsetr (xc, APODIZE, max (0.0, min (rval, 0.50)))
newdata = YES; newcross = YES; newcenter = YES
}
case XCMD_CORRELATION:
call gargwrd (Memc[cmd], SZ_LINE)
if (Memc[cmd] == EOS) {
call rg_xstats (xc, CSTRING, Memc[str], SZ_FNAME)
call printf ("%s = %s\n")
call pargstr (KY_CORRELATION)
call pargstr (Memc[str])
} else {
stat = strdic (Memc[cmd], Memc[cmd], SZ_LINE, XC_CTYPES)
if (stat > 0) {
call rg_xseti (xc, CFUNC, stat)
call rg_xsets (xc, CSTRING, Memc[cmd])
newcross = YES; newcenter = YES
}
}
case XCMD_XWINDOW:
call gargi (ival)
if (nscan() == 1) {
call printf ("%s = %d\n")
call pargstr (KY_XWINDOW)
call pargi (rg_xstati (xc, XWINDOW))
} else {
call rg_xseti (xc, XWINDOW, ival)
newdata = YES; newcross = YES; newcenter = YES
}
case XCMD_YWINDOW:
call gargi (ival)
if (nscan() == 1) {
call printf ("%s = %d\n")
call pargstr (KY_YWINDOW)
call pargi (rg_xstati (xc, YWINDOW))
} else {
call rg_xseti (xc, YWINDOW, ival)
newdata = YES; newcross = YES; newcenter = YES
}
case XCMD_PEAKCENTER:
call gargwrd (Memc[cmd], SZ_LINE)
if (Memc[cmd] == EOS) {
call rg_xstats (xc, PSTRING, Memc[str], SZ_FNAME)
call printf ("%s: %s\n")
call pargstr (KY_PEAKCENTER)
call pargstr (Memc[str])
} else {
stat = strdic (Memc[cmd], Memc[cmd], SZ_LINE, XC_PTYPES)
if (stat > 0) {
call rg_xseti (xc, PFUNC, stat)
call rg_xsets (xc, PSTRING, Memc[cmd])
newcenter = YES
}
}
case XCMD_XCBOX:
call gargi (ival)
if (nscan() == 1) {
call printf ("%s = %d\n")
call pargstr (KY_XCBOX)
call pargi (rg_xstati (xc, XCBOX))
} else {
if (mod (ival, 2) == 0)
ival = ival + 1
call rg_xseti (xc, XCBOX, ival)
newcenter = YES
}
case XCMD_YCBOX:
call gargi (ival)
if (nscan() == 1) {
call printf ("%s = %g\n")
call pargstr (KY_YCBOX)
call pargi (rg_xstati (xc, YCBOX))
} else {
if (mod (ival, 2) == 0)
ival = ival + 1
call rg_xseti (xc, YCBOX, ival)
newcenter = YES
}
case XCMD_SHOW:
call gdeactivate (gd, 0)
call gargwrd (Memc[cmd], SZ_LINE)
ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, XSHOW)
switch (ncmd) {
case XSHOW_DATA:
call rg_xnshow (xc)
case XSHOW_BACKGROUND:
call rg_xbshow (xc)
case XSHOW_CORRELATION:
call rg_xxshow (xc)
case XSHOW_PEAKCENTER:
call rg_xpshow (xc)
default:
call rg_xshow (xc)
}
call greactivate (gd, 0)
case XCMD_MARK:
call gdeactivate (gd, 0)
if (reglist != NULL) {
call fntclsb (reglist)
reglist = NULL
}
if (rg_xmkregions (imr, xc, 1, MAX_NREGIONS, Memc[str],
SZ_LINE) <= 0) {
call rg_xstats (xc, REGIONS, Memc[str], SZ_LINE)
iferr (reglist = fntopnb (Memc[str], NO))
reglist = NULL
if (rg_xregions (reglist, imr, xc, 1) > 0)
;
call rg_xsets (xc, REGIONS, Memc[str])
call rg_xseti (xc, CREGION, 1)
} else {
call rg_xseti (xc, CREGION, 1)
call rg_xsets (xc, REGIONS, Memc[str])
newdata = YES; newcross = YES; newcenter = YES
}
call greactivate (gd, 0)
default:
call printf ("Unknown or ambiguous colon command\7\n")
}
call sfree (sp)
end
|