aboutsummaryrefslogtreecommitdiff
path: root/noao/onedspec/irsiids/t_coefs.x
blob: 656e777d08187d23b66939b36d97ab4b7fc7cbb9 (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
include	<error.h>

# COEFS --  Convert IIDS/IRS coeffients to IDENTIFY database entry.

procedure t_coefs ()

int	root			# List of input root names
pointer	database		# Output database directory

int	i, nrecs, ncoefs
real	coef
pointer	sp, image, dtname, recs, im, dt

real	imgetr()
int	clpopni(), imgeti(), get_next_image(), decode_ranges()
pointer	immap(), dtmap1()
errchk	imgetr, dtmap1

begin
	call smark (sp)
	call salloc (image, SZ_LINE, TY_CHAR)
	call salloc (database, SZ_FNAME, TY_CHAR)
	call salloc (dtname, SZ_FNAME, TY_CHAR)
	call salloc (recs, 300, TY_INT)

	root   = clpopni ("input")
	call clgstr ("records", Memc[image], SZ_LINE)
	call clgstr ("database", Memc[database], SZ_LINE)

	if (decode_ranges (Memc[image], Memi[recs], 100, nrecs) == ERR)
	    call error (0, "Bad range specification")

	# Loop over all input images - print name on STDOUT
	call reset_next_image ()
	while (get_next_image (root, Memi[recs], nrecs, Memc[image],
	    SZ_LINE) != EOF) {
	    iferr (im = immap (Memc[image], READ_ONLY, 0)) {
		call erract (EA_WARN)
		next
	    }

	    iferr (ncoefs = imgeti (im, "DF-FLAG"))
		ncoefs = -1
	    if (ncoefs > 1) {
		call strcpy ("id", Memc[dtname], SZ_FNAME)
		call imgcluster (Memc[image], Memc[dtname+2], SZ_FNAME)
		dt = dtmap1 (Memc[database], Memc[dtname], APPEND)

		call dtptime (dt)
		call dtput (dt, "begin\tidentify %s\n")
		    call pargstr (Memc[image])
		call dtput (dt, "\tid\t%s\n")
		    call pargstr (Memc[image])
		call dtput (dt, "\ttask\tidentify\n")
		call dtput (dt, "\timage\t%s\n")
		    call pargstr (Memc[image])

		# Convert coefficients
		call dtput (dt, "\tcoefficients\t%d\n")
		    call pargi (ncoefs+4)
		call dtput (dt, "\t\t2\n")
		call dtput (dt, "\t\t%1d\n")
		    call pargi (ncoefs)
		call dtput (dt, "\t\t1\n")
		call dtput (dt, "\t\t1024\n")

		do i = 1, ncoefs {
		    call sprintf (Memc[dtname], SZ_FNAME, "DF%d")
			call pargi (i)
		    coef = imgetr (im, Memc[dtname])
		    call dtput (dt, "\t\t%10.4f\n")
			call pargr (coef)
		}

		call dtput (dt, "\n")
		call dtunmap (dt)
	    }

	    call printf ("[%s] %d coefficients written\n")
		call pargstr (Memc[image])
		call pargi (max (0, ncoefs))
	    call flush (STDOUT)
	    call imunmap (im)
	}

	call clpcls (root)
	call sfree (sp)
end