aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/photcal/evaluate/phcheck.x
blob: 2f72993027b7bc2b5f93d0c153890b4acc54b8aa (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
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
include "../lib/parser.h"
include "../lib/preval.h"

# PH_SETEQN -- Determine whether a PHOTCAL expression includes any set
# equations which contain references to catalog variables. Return a YES
# or NO status.

int procedure ph_seteqn (code)

pointer	code			# the photcal equation code

int	ip, ins
pointer	setcode
int	pr_geti(), pr_gsym(), ph_cateqn()
pointer	pr_gsymp()

begin
	# Return NO if there are no defined set equations.
	if (pr_geti (NSETEQS) <= 0)
	    return (NO)

	# Initialize.
	ip = 0  
	ins = Memi[code+ip]

	# Loop over the equation parsing instructions.
	while (ins != PEV_EOC) {

	    switch (ins) {
	    case PEV_SETEQ:
		ip = ip + 1
		setcode = pr_gsymp (pr_gsym (Memi[code+ip], PTY_SETEQ),
		    PSEQRPNEQ)
		if (ph_cateqn (setcode) == YES)
		    return (YES)
	    case PEV_NUMBER, PEV_CATVAR, PEV_OBSVAR, PEV_PARAM:
		ip = ip + 1
	    case PEV_EXTEQ, PEV_TRNEQ:
		ip = ip + 1
	    default:
		# do nothing
	    }

	    ip = ip + 1
	    ins = Memi[code+ip]
	}

	return (NO)
end


# PH_CATEQN -- Given a PHOTCAL set equation determine whether there are any
# references in it to catalog variables. Return a YES or NO status.

int procedure ph_cateqn (code)

pointer	code		# pointer to the equation code

int	ip, ins
int	pr_geti()

begin
	# Return NO if there are no catalog variables.
	if (pr_geti (NCATVARS) <= 0)
	    return (NO)

	# Initialize.
	ip = 0  
	ins = Memi[code+ip]

	# Loop over the equation parsing instructions.
	while (ins != PEV_EOC) {

	    switch (ins) {
	    case PEV_CATVAR:
		return (YES)
	    case  PEV_NUMBER, PEV_OBSVAR, PEV_PARAM:
		ip = ip + 1
	    case PEV_SETEQ, PEV_EXTEQ, PEV_TRNEQ:
		ip = ip + 1
	    default:
		# do nothing
	    }

	    ip = ip + 1
	    ins = Memi[code+ip]
	}

	return (NO)
end


# PH_SETVAR -- Check to see whether the fit expression portion of a PHOTCAL
# transformation equation contains references to set equations which include
# previously unreferenced catalog variables. Return the number of previously
# unreferenced set equations.

int procedure ph_setvar (eqn, sym, cmap, omap, tuservars, uservars, usererrs,
	nstdvars, nobsvars, eqset, maxnset, userset, nset)

int	eqn			# the equation number
pointer	sym			# pointer to the equation symbol
pointer	cmap			# pointer to catalog variable column map
pointer	omap			# pointer to observations variable column map
int	tuservars[nstdvars,ARB]	# list of active catalog variables per equation
int	uservars[ARB]		# list of active catalog variables
int	usererrs[ARB]		# list of active observational error columns
int	nstdvars		# total number of catalog variables
int	nobsvars		# total number of observations variables
int	eqset[maxnset,ARB]	# set equation table
int	maxnset			# maximum number of set equations
int	userset[ARB]		# the list of active set equations
int	nset			# number of set equations

bool	new
int	i, ip, ins, nvar
pointer	fitcode, setsym
int	pr_gsym(), ph_catvar()
pointer	pr_gsymp()

begin
	# Get the fit expression symbols.
	fitcode = pr_gsymp (sym, PTEQRPNFIT)

	# Initialize.
	nvar = 0
	ip = 0  
	ins = Memi[fitcode+ip]

	# Loop over the fit expression.
	while (ins != PEV_EOC) {

	    switch (ins) {
	    case PEV_SETEQ:
		ip = ip + 1
		setsym = pr_gsym (Memi[fitcode+ip], PTY_SETEQ)
		if (ph_catvar (eqn, setsym, cmap, omap, tuservars, uservars,
		    usererrs, nstdvars, nobsvars) == YES) {
		    new = true
		    do i = 1, nset + nvar {
			if (setsym != userset[i])
			    next
			eqset[i,eqn] = setsym
			new = false
			break
		    }
		    if (new) {
			nvar = nvar + 1
			eqset[nset+nvar,eqn] = setsym
			userset[nset+nvar] = setsym 
		    }
		}
	    case PEV_NUMBER, PEV_CATVAR, PEV_OBSVAR, PEV_PARAM:
		ip = ip + 1
	    case PEV_EXTEQ, PEV_TRNEQ:
		ip = ip + 1
	    default:
		# do nothing
	    }

	    ip = ip + 1
	    ins = Memi[fitcode+ip]
	}

	return (nvar)
end


# PH_CATVAR -- Determine whether any catalog variables in the set
# equation have not been previously referenced in the transformation
# equations.

int procedure ph_catvar (eqn, setsym, cmap, omap, tuservars, uservars,
	usererrs, nstdvars, nobsvars)

int	eqn			# the transformation equation number
int	setsym			# the set equation symbol
pointer	cmap			# pointer to catalog variable column map
pointer	omap			# pointer to observations variable column map
int	tuservars[nstdvars,ARB]	# active variables as a function of eqn
int	uservars[ARB]		# currently active catalog variables
int	usererrs[ARB]		# currently active observations varaiables errs
int	nstdvars		# the total number of catalog variables
int	nobsvars		# the total number of observations variables

int	setcode, ip, ins, stat, vcol, ecol
pointer	catsym, obsym
int	pr_gsym(), pr_gsymi(), pr_findmap1()
pointer	pr_gsymp()

begin
	# Get the set equation code.
	setcode = pr_gsymp (setsym, PSEQRPNEQ)

	# Initialize.
	ip = 0  
	ins = Memi[setcode+ip]
	stat = NO

	while (ins != PEV_EOC) {

	    switch (ins) {
	    case PEV_CATVAR:
		ip = ip + 1
		catsym = pr_gsym (Memi[setcode+ip] - nobsvars, PTY_CATVAR)
		vcol = pr_gsymi (catsym, PINPCOL)
		vcol = pr_findmap1 (cmap, vcol)
		if (uservars[vcol] <= 0) {
		    tuservars[vcol,eqn] = -(vcol + nobsvars)
		    uservars[vcol] = -(vcol + nobsvars)
		    stat = YES
		}

	    case PEV_OBSVAR:
		ip = ip + 1
		obsym = pr_gsym (Memi[setcode+ip], PTY_OBSVAR)
		vcol = pr_gsymi (obsym, PINPCOL)
		ecol = pr_gsymi (obsym, PINPERRCOL)
		vcol = pr_findmap1 (omap, vcol)
		if (! IS_INDEFI(ecol))
		    ecol = pr_findmap1 (omap, ecol)
		if (! IS_INDEFI(ecol))
		    usererrs[vcol] = ecol

	    case PEV_NUMBER, PEV_PARAM:
		ip = ip + 1

	    case PEV_SETEQ, PEV_EXTEQ, PEV_TRNEQ:
		ip = ip + 1

	    default:
		# do nothing
	    }

	    ip = ip + 1
	    ins = Memi[setcode+ip]
	}

	return (stat)
end