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
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <ctype.h>
include <qpioset.h>
include "qpf.h"
# QPF_WATTR -- Record information about the attributes of the filter
# expression used to generate an image. Currently the only value which can be
# computed and recorded is total range (integral of the in-range intervals) of
# the range list defining an attribute, for example, the total exposure time
# defined by the time range list used to filter the data.
#
# This routine is driven by a set of optional QPOE header keywords of the
# form
#
# Keyword String Value
#
# defattrN <param-name> = "integral" <attribute-name>[:type]
# e.g.
# defattr1 "exptime = integral time:d"
#
# where param-name is the parameter name to be written to the output image
# header, "integral" is the value to be computed, and attribute-name is the
# QPEX attribute (e.g., "time") to be used for the computation. A finite
# value is returned for the integral if a range list is given for the named
# attribute and the range is closed. If the range is open on either or both
# ends, or no range expression is defined for the attribute, then INDEF is
# returned for the value of the integral.
procedure qpf_wattr (qpf, im)
pointer qpf #I QPF descriptor
pointer im #I image descriptor
real r1, r2, rsum
double d1, d2, dsum
int dtype, i, j, xlen, nranges, i1, i2, isum
pointer sp, io, qp, ex, kwname, kwval, pname, funame, atname, ip, xs, xe
bool strne()
pointer qpio_stati()
int qp_gstr(), ctowrd(), qp_accessf()
int qpex_attrli(), qpex_attrlr(), qpex_attrld()
errchk qpex_attrli, qpex_attrlr, qpex_attrld, imaddi, imaddr, imaddd
begin
io = QPF_IO(qpf)
if (io == NULL)
return
qp = QPF_QP(qpf)
ex = qpio_stati (io, QPIO_EX)
call smark (sp)
call salloc (kwname, SZ_FNAME, TY_CHAR)
call salloc (kwval, SZ_LINE, TY_CHAR)
call salloc (pname, SZ_FNAME, TY_CHAR)
call salloc (funame, SZ_FNAME, TY_CHAR)
call salloc (atname, SZ_FNAME, TY_CHAR)
# Process a sequence of "defattrN" header parameter definitions.
# Each defines a parameter to be computed and added to the output
# image header.
do i = 1, ARB {
# Check for a parameter named "defattrN", get string value.
call sprintf (Memc[kwname], SZ_FNAME, "defattr%d")
call pargi (i)
if (qp_accessf (qp, Memc[kwname]) == NO)
break
if (qp_gstr (qp, Memc[kwname], Memc[kwval], SZ_LINE) <= 0)
break
# Parse string value into parameter name, function name,
# expression attribute name, and datatype.
ip = kwval
if (ctowrd (Memc, ip, Memc[pname], SZ_FNAME) <= 0)
break
while (IS_WHITE(Memc[ip]) || Memc[ip] == '=')
ip = ip + 1
if (ctowrd (Memc, ip, Memc[funame], SZ_FNAME) <= 0)
break
if (ctowrd (Memc, ip, Memc[atname], SZ_FNAME) <= 0)
break
dtype = TY_INT
for (ip=atname; Memc[ip] != EOS; ip=ip+1)
if (Memc[ip] == ':') {
Memc[ip] = EOS
if (Memc[ip+1] == 'd')
dtype = TY_DOUBLE
else if (Memc[ip+1] == 'r')
dtype = TY_REAL
else
call eprintf ("QPF.defattr: datatype not recognized\n")
}
# Verify known function type.
if (strne (Memc[funame], "integral")) {
call eprintf ("QPF.defattr: function `%s' not recognized\n")
call pargstr (Memc[funame])
break
}
# Compute the integral of the range list for the named attribute.
xlen = 0
xs = NULL
xe = NULL
switch (dtype) {
case TY_REAL:
if (ex == NULL)
nranges = 0
else
nranges = qpex_attrlr (ex, Memc[atname], xs, xe, xlen)
if (nranges <= 0)
rsum = INDEFR
else {
rsum = 0
do j = 1, nranges {
r1 = Memr[xs+j-1]
r2 = Memr[xe+j-1]
if (IS_INDEFR(r1) || IS_INDEFR(r2)) {
rsum = INDEFR
break
} else
rsum = rsum + (r2 - r1)
}
}
call mfree (xs, TY_REAL)
call mfree (xe, TY_REAL)
call imaddr (im, Memc[pname], rsum)
case TY_DOUBLE:
if (ex == NULL)
nranges = 0
else
nranges = qpex_attrld (ex, Memc[atname], xs, xe, xlen)
if (nranges <= 0)
dsum = INDEFD
else {
dsum = 0
do j = 1, nranges {
d1 = Memd[xs+j-1]
d2 = Memd[xe+j-1]
if (IS_INDEFD(d1) || IS_INDEFD(d2)) {
dsum = INDEFD
break
} else
dsum = dsum + (d2 - d1)
}
}
call mfree (xs, TY_DOUBLE)
call mfree (xe, TY_DOUBLE)
call imaddd (im, Memc[pname], dsum)
default:
if (ex == NULL)
nranges = 0
else
nranges = qpex_attrli (ex, Memc[atname], xs, xe, xlen)
if (nranges <= 0)
isum = INDEFI
else {
isum = 0
do j = 1, nranges {
i1 = Memi[xs+j-1]
i2 = Memi[xe+j-1]
if (IS_INDEFI(i1) || IS_INDEFI(i2)) {
isum = INDEFI
break
} else
isum = isum + (i2 - i1)
}
}
call mfree (xs, TY_INT)
call mfree (xe, TY_INT)
call imaddi (im, Memc[pname], isum)
}
}
call sfree (sp)
end
|