aboutsummaryrefslogtreecommitdiff
path: root/noao/twodspec/apextract/apparams.x
blob: 526b4bcd726e54cb95835140eecbf4fd8e7c8d28 (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
define	PARAMS		"apextract$apparams.dat"
define	LEN_LINE	80

# AP_PARAMS -- Show the parameters.

procedure ap_params (file, image, line, nsum)

char	file[ARB]		# Aperture file
char	image[ARB]		# Image name
int	line			# Image line
int	nsum			# Number of lines to sum

int	in, out, len, nchar
pointer	sp, param, type, format, instr, outstr, str
bool	apgetb()
int	apgeti(), open(), fscan(), nscan(), strlen()
real	apgetr()
errchk	open

begin
	# Open input parameter file and output stream.
	in = open (PARAMS, READ_ONLY, TEXT_FILE)
	out = open (file, APPEND, TEXT_FILE)

	call smark (sp)
	call salloc (param, SZ_LINE, TY_CHAR)
	call salloc (type, 10, TY_CHAR)
	call salloc (format, 10, TY_CHAR)
	call salloc (instr, SZ_LINE, TY_CHAR)
	call salloc (outstr, SZ_LINE, TY_CHAR)
	call salloc (str, SZ_LINE, TY_CHAR)
	Memc[outstr] = EOS

	call fprintf (out, "%32tAPEXTRACT PARAMETERS\n")
	call fprintf (out, "image=%s%27tline=%d%53tnsum=%d\n")
	    call pargstr (image)
	    call pargi (line)
	    call pargi (nsum)
	call fprintf (out, "database=%s%27tlogfile=%s%53tplotfile=%s\n\n")
	    call clgstr ("database", Memc[str], SZ_LINE)
	    call pargstr (Memc[str])
	    call clgstr ("logfile", Memc[str], SZ_LINE)
	    call pargstr (Memc[str])
	    call clgstr ("plotfile", Memc[str], SZ_LINE)
	    call pargstr (Memc[str])

	len = 0
	while (fscan (in) != EOF) {
	    call gargwrd (Memc[param], SZ_LINE)
	    call gargwrd (Memc[type], 10)
	    call gargwrd (Memc[format], 10)
	    call gargi (nchar)
	    if (nscan() < 4)
		nchar = LEN_LINE

	    if (len + nchar > LEN_LINE) {
		call strcat ("\n", Memc[outstr], SZ_LINE)
		call fprintf (out, Memc[outstr])
		Memc[outstr] = EOS
		len = 0
	    }

	    if (nscan() == 1) {
		call sprintf (Memc[outstr], SZ_LINE, "%%%dt%s")
		    call pargi ((LEN_LINE - strlen (Memc[param])) / 2)
		    call pargstr (Memc[param])
	    } else if (nscan() == 4) {
	        call sprintf (Memc[str], SZ_LINE, "%%%dt%s=")
		    call pargi (len+1)
		    call pargstr (Memc[param])
	        call strcat (Memc[str], Memc[outstr], SZ_LINE)

	        call sprintf (Memc[str], SZ_LINE, Memc[format])
	        switch (Memc[type]) {
	        case 'b':
		    call pargb (apgetb (Memc[param]))
	        case 'i':
		    call pargi (apgeti (Memc[param]))
	        case 'r':
		    call pargr (apgetr (Memc[param]))
	        case 's':
		    call apgstr (Memc[param], Memc[instr], SZ_LINE)
		    call pargstr (Memc[instr])
	        }
	        call strcat (Memc[str], Memc[outstr], SZ_LINE)
	    }
	    len = len + nchar
	}
	call strcat ("\n", Memc[outstr], SZ_LINE)
	call fprintf (out, Memc[outstr])

	call close (in)
	call close (out)
	call sfree (sp)
end