aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/ptools/pexamine/ptsetup.x
blob: 5a8bc832a83fb97efc04661dc8277a3cf0a3e56b (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
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
include <error.h>
include <ctotok.h>
include "pexamine.h"

# PT_INIT - Initialize the pexamine structure.

pointer procedure pt_init (photcols, usercols, xcol, ycol, xpos, ypos, hcol)

char	photcols[ARB]		# the list of photometry columns
char	usercols[ARB]		# the list of user columns
char	xcol[ARB]		# the name of the x column
char	ycol[ARB]		# the name of the y column
char	xpos[ARB]		# the name of the x coord column
char	ypos[ARB]		# the name of the y coord column
char	hcol[ARB]		# the name of the histogram column

pointer	px
bool	streq()
int	strdic()

begin
	# Preload the daophot and apphot photometry fields.
	if (streq ("DAOPHOT", photcols) || streq ("daophot", photcols))
	    call strcpy (PX_DAOCOLS, photcols, PX_SZCOLNAME * (PX_MAXNCOLS + 1))
	else if (streq ("APPHOT", photcols) || streq ("apphot", photcols))
	    call strcpy (PX_APCOLS, photcols, PX_SZCOLNAME * (PX_MAXNCOLS + 1))

	# Allocate space for the pexamine structure and the column lists.
	call malloc (px, LEN_PXSTRUCT, TY_STRUCT)

	# Initialize the requested column information.
	PX_RNPHOT(px) = 0; PX_RNUSER(px) = 0; PX_RNCOLS(px) = 0
	call malloc (PX_RCOLNAMES(px), PX_SZCOLNAME * (PX_MAXNCOLS + 1),
	    TY_CHAR)
	Memc[PX_RCOLNAMES(px)] = EOS

	# Initialize the stored column information.
	PX_NPHOT(px) = 0; PX_NUSER(px) = 0; PX_NCOLS(px) = 0
	call malloc (PX_COLNAMES(px), PX_SZCOLNAME * (PX_MAXNCOLS + 1),
	    TY_CHAR)
	Memc[PX_COLNAMES(px)] = EOS

	# Decode the column strings. Check that the number of columns
	# does not exceed the maximum number permitted, by extracting
	# the column names one by one from the photometry and user column
	# strings.

	call pt_setnames (px, photcols, usercols)

	# Convert all the input column name specifications to upper case.
	call strupr (xcol)
	call strupr (ycol)
	call strupr (xpos)
	call strupr (ypos)
	call strupr (hcol)

	# Decode the x and y columns.
	if (strdic (xcol, PX_RXCOLNAME(px), PX_SZCOLNAME,
	    Memc[PX_RCOLNAMES(px)]) <= 0)
	    call strcpy (xcol, PX_RXCOLNAME(px), PX_SZCOLNAME)
	if (strdic (ycol, PX_RYCOLNAME(px), PX_SZCOLNAME,
	    Memc[PX_RCOLNAMES(px)]) <= 0)
	    call strcpy (ycol, PX_RYCOLNAME(px), PX_SZCOLNAME)

	# Decode the y and y coordinate column names.
	if (strdic (xpos, PX_RXPOSNAME(px), PX_SZCOLNAME,
	    Memc[PX_RCOLNAMES(px)]) <= 0)
	    call strcpy (xpos, PX_RXPOSNAME(px), PX_SZCOLNAME)
	if (strdic (ypos, PX_RYPOSNAME(px), PX_SZCOLNAME,
	    Memc[PX_RCOLNAMES(px)]) <= 0)
	    call strcpy (ypos, PX_RYPOSNAME(px), PX_SZCOLNAME)

	# Decode the histogram column name.
	if (strdic (hcol, PX_RHCOLNAME(px), PX_SZCOLNAME,
	    Memc[PX_RCOLNAMES(px)]) <= 0)
	    call strcpy (hcol, PX_RHCOLNAME(px), PX_SZCOLNAME)

	# Allocate space for the pointers and initialize them to NULL.
	call malloc (PX_COLPTRS(px), PX_MAXNCOLS, TY_POINTER)
	call amovki (NULL, Memi[PX_COLPTRS(px)], PX_MAXNCOLS) 

	return (px)
end


# PT_FREE -- Free memory used by the pexamine task.

procedure pt_free (px)

pointer	px

int	i

begin
	# Free the column lists.
	if (PX_RCOLNAMES(px) != NULL)
	    call mfree (PX_RCOLNAMES(px), TY_CHAR)
	if (PX_COLNAMES(px) != NULL)
	    call mfree (PX_COLNAMES(px), TY_CHAR)

	# Free the column pointers.
	do i = 1, PX_MAXNCOLS {
	    if (Memi[PX_COLPTRS(px)+i-1] != NULL)
		call mfree (Memi[PX_COLPTRS(px)+i-1], TY_REAL)
	}
	if (PX_COLPTRS(px) != NULL)
	    call mfree (PX_COLPTRS(px), TY_POINTER)

	# Free the pexamine structure.
	call mfree (px, TY_STRUCT)
end


# PT_SETNAMES -- Decode the photometry and user columns.

procedure pt_setnames (px, photcols, usercols)

pointer	px			# pointer to the pexamine strucuture
char	photcols[ARB]		# list of photometry columns
char	usercols[ARB]		# list of user columns

int	ip, nphot
pointer	sp, name
int	pt_getnames()

begin
	call smark (sp)
	call salloc (name, PX_SZCOLNAME, TY_CHAR)

	call strupr (photcols)
	call strupr (usercols)
	Memc[PX_RCOLNAMES(px)] = EOS

	ip = 1
	nphot = 0
	while (pt_getnames (photcols, ip, Memc[name], PX_SZCOLNAME) != EOF) {
	    if (nphot >= PX_MAXNCOLS)
		break
	    #if (Memc[name] == EOS)
		#next
	    call strcat (",", Memc[PX_RCOLNAMES(px)], PX_SZCOLNAME *
		(PX_MAXNCOLS + 1))
	    call strcat (Memc[name], Memc[PX_RCOLNAMES(px)], PX_SZCOLNAME *
		(PX_MAXNCOLS + 1))
	    nphot = nphot + 1
	}
	PX_RNPHOT(px) = nphot

	# Decode the user columns.
	ip = 1
	while (pt_getnames (usercols, ip, Memc[name], PX_SZCOLNAME) != EOF) {
	    if (nphot >= PX_MAXNCOLS)
		break
	    #if (Memc[name] == EOS)
		#next
	    call strcat (",", Memc[PX_RCOLNAMES(px)], PX_SZCOLNAME *
	        (PX_MAXNCOLS + 1))
	    call strcat (Memc[name], Memc[PX_RCOLNAMES(px)], PX_SZCOLNAME *
		(PX_MAXNCOLS + 1))
	    nphot = nphot + 1
	}
	PX_RNUSER(px) = nphot - PX_RNPHOT(px)

	PX_RNCOLS(px) = nphot

	call sfree (sp)
end


# PT_GPHOTCOLS -- Extract the requested and stored photometric columns
# from the pexamine structure.

procedure pt_gphotcols (px, rphotcols, rnphot, photcols, nphot)

pointer	px		# pointer to the pexamine structure
char	rphotcols[ARB]	# list of requested photometric columns
int	rnphot		# number of requested photometric columns
char	photcols[ARB]	# list of photometric columns
int	nphot		# number of photometric columns

int	ip, ncols
pointer	sp, name
int	pt_getnames()

begin
	call smark (sp)
	call salloc (name, PX_SZCOLNAME, TY_CHAR)

	ip = 1
	ncols = 0
	rphotcols[1] = EOS
	while (pt_getnames (Memc[PX_RCOLNAMES(px)], ip, Memc[name],
	    PX_SZCOLNAME) != EOF) {
	    #if (Memc[name] == EOS)
		#next
	    ncols = ncols + 1
	    if (ncols > PX_RNPHOT(px))
		break
	    call strcat (",", rphotcols, PX_SZCOLNAME * (PX_MAXNCOLS + 1))
	    call strcat (Memc[name], rphotcols, PX_SZCOLNAME *
	        (PX_MAXNCOLS + 1))
	}
	rnphot = PX_RNPHOT(px)

	ip = 1
	ncols = 0
	photcols[1] = EOS
	while (pt_getnames (Memc[PX_COLNAMES(px)], ip, Memc[name],
	    PX_SZCOLNAME) != EOF) {
	    #if (Memc[name] == EOS)
		#next
	    ncols = ncols + 1
	    if (ncols > PX_NPHOT(px))
		break
	    call strcat (",", photcols, PX_SZCOLNAME * (PX_MAXNCOLS + 1))
	    call strcat (Memc[name], photcols, PX_SZCOLNAME *
	        (PX_MAXNCOLS + 1))
	}
	nphot = PX_NPHOT(px)

	call sfree (sp)
end


# PT_GUSERCOLS -- Extract the requested and stored user columns
# from the pexamine structure.

procedure pt_gusercols (px, rusercols, rnuser, usercols, nuser)

pointer	px		# pointer to the pexamine structure
char	rusercols[ARB]	# list of requested user columns
int	rnuser		# number of requested user columns
char	usercols[ARB]	# list of user columns
int	nuser		# number of user columns

int	ip, ncols
pointer	sp, name
int	pt_getnames()

begin
	call smark (sp)
	call salloc (name, PX_SZCOLNAME, TY_CHAR)

	ip = 1
	ncols = 0
	rusercols[1] = EOS
	while (pt_getnames (Memc[PX_RCOLNAMES(px)], ip, Memc[name],
	    PX_SZCOLNAME) != EOF) {
	    #if (Memc[name] == EOS)
		#next
	    ncols = ncols + 1
	    if (ncols <= PX_RNPHOT(px))
		next
	    call strcat (",", rusercols, PX_SZCOLNAME * (PX_MAXNCOLS + 1))
	    call strcat (Memc[name], rusercols, PX_SZCOLNAME *
	        (PX_MAXNCOLS + 1))
	}
	rnuser = PX_RNUSER(px)

	ip = 1
	ncols = 0
	usercols[1] = EOS
	while (pt_getnames (Memc[PX_COLNAMES(px)], ip, Memc[name],
	    PX_SZCOLNAME) != EOF) {
	    #if (Memc[name] == EOS)
		#next
	    ncols = ncols + 1
	    if (ncols <= PX_NPHOT(px))
		next
	    call strcat (",", usercols, PX_SZCOLNAME * (PX_MAXNCOLS + 1))
	    call strcat (Memc[name], usercols, PX_SZCOLNAME *
	        (PX_MAXNCOLS + 1))
	}
	nuser = PX_NUSER(px)

	call sfree (sp)
end


# PT_LCOLS -- List the requested and stored columns with an optional
# title string.

procedure pt_lcols (title, rcols, rncols, cols, ncols)

char	title[ARB]		# title string for column listing
char	rcols[ARB]		# list of requested columns
int	rncols			# the number of requested columns
char	cols[ARB]		# list of stored columns
int	ncols			# the number of stored columns

int	ip1, ip2, i
pointer	sp, name1, name2
int	pt_getnames()

begin
	call smark (sp)
	call salloc (name1, PX_SZCOLNAME, TY_CHAR)
	call salloc (name2, PX_SZCOLNAME, TY_CHAR)

	call printf ("\n%s\n\n")
	    call pargstr (title)

	ip1 = 1
	ip2 = 1
	do i = 1, max (rncols, ncols) {
	    if (pt_getnames (rcols, ip1, Memc[name1], PX_SZCOLNAME) == EOF)
		Memc[name1] = EOS
	    if (pt_getnames (cols, ip2, Memc[name2], PX_SZCOLNAME) == EOF)
		Memc[name2] = EOS
	    call printf ("    requested: %*.*s    stored: %*.*s\n")
		call pargi (-PX_SZCOLNAME)
		call pargi (PX_SZCOLNAME)
		call pargstr (Memc[name1])
		call pargi (-PX_SZCOLNAME)
		call pargi (PX_SZCOLNAME)
		call pargstr (Memc[name2])
	}

	call sfree (sp)
end


# PT_GETNAMES -- Decode the list of column names into list of column names.

int procedure pt_getnames (colnames, ip, name, maxch)

char	colnames[ARB]		# list of column names	
int	ip			# pointer in to the list of names
char	name[ARB]		# the output column name
int	maxch			# maximum length of a column name

int	op, token
int	ctotok(), strlen()

begin
	# Decode the column labels.
	op = 1
	while (colnames[ip] != EOS) {

	    token = ctotok (colnames, ip, name[op], maxch)
	    if (name[op] == EOS)
		next
	    if ((token == TOK_UNKNOWN) || (token == TOK_CHARCON))
		break
	    if ((token == TOK_PUNCTUATION) && (name[op] == ',')) {
		if (op == 1)
		    next
		else
		    break
	    }

	    op = op + strlen (name[op])
	}

	name[op] = EOS
	if ((colnames[ip] == EOS) && (op == 1))
	    return (EOF)
	else
	    return (op - 1)
end