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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
include <error.h>
include <time.h>
include "../lib/io.h"
# IO_GCATDAT - Get catalog data from a list of files. These data will be
# stored in memory as a symbol table for later use.
procedure io_gcatdat (catdir, list, ctable, ncat, nvars)
char catdir[ARB] # name of the catalog directory
int list # file list
pointer ctable # catalog table (output)
int ncat # number of table entries (output)
int nvars # number of catalog variables
int i, fd, num, col, ip, tp, index
pointer sp, input, fname, line, token, dummy, indices, sym, map
real rval
#bool clgetb()
int fntgfnb(), access(), ctowrd(), ctor(), open(), stnsymbols()
int pr_findmap(), io_getline(), io_lineid()
pointer stopen(), stfind(), stenter()
begin
# Debug ?
#if (clgetb ("debug.iocode")) {
#call eprintf ("io_gcatdat.in: (list=%d) (nvars=%d)\n")
#call pargi (list)
#call pargi (nvars)
#}
# Map catalog variables.
call pr_catmap (map, nvars)
# Open a symbol table for catalog data.
ctable = stopen ("catalog", 2 * LEN_CATDAT, LEN_CATDAT,
10 * LEN_CATDAT)
# Allocate temporary space.
call smark (sp)
call salloc (input, SZ_FNAME, TY_CHAR)
call salloc (fname, SZ_FNAME, TY_CHAR)
call salloc (line, MAX_CONT * SZ_LINE, TY_CHAR)
call salloc (token, SZ_LINE, TY_CHAR)
call salloc (dummy, SZ_LINE, TY_CHAR)
call salloc (indices, nvars, TY_INT)
# Read the catalog data.
call fntrewb (list)
while (fntgfnb (list, Memc[input], SZ_FNAME) != EOF) {
# Create the file name.
call sprintf (Memc[fname], SZ_FNAME, "%s%s.dat")
call pargstr (catdir)
call pargstr (Memc[input])
if (access (Memc[fname], READ_ONLY, TEXT_FILE) == NO)
call strcpy (Memc[input], Memc[fname], SZ_FNAME)
# Try to open the input file.
iferr (fd = open (Memc[fname], READ_ONLY, TEXT_FILE)) {
call erract (EA_WARN)
next
}
# Read the file lines.
call io_getline_init ()
while (io_getline (fd, Memc[line], MAX_CONT * SZ_LINE) != EOF) {
# Get the line id from the first column.
ip = 1
if (io_lineid (Memc[line], ip, Memc[dummy], Memc[token],
SZ_LINE) == 0)
next
# Enter the line identifier in the symbol table.
if (stfind (ctable, Memc[token]) == NULL) {
sym = stenter (ctable, Memc[token], nvars)
call amovkr (INDEFR, Memr[P2R(sym)], nvars)
} else
next
# Get the values from the next columns.
col = 2
while (ctowrd (Memc[line], ip, Memc[token], SZ_LINE) > 0) {
# Enter value into symbol table if it was declared in the
# configuration file.
tp = 1
if (ctor (Memc[token], tp, rval) > 0) {
num = pr_findmap (map, col, Memi[indices], nvars)
do i = 1, num {
index = Memi[indices+i-1]
if (! IS_INDEFI (index))
Memr[P2R(sym+index-1)] = rval
}
}
# Count columns
col = col + 1
}
}
# Close file
call close (fd)
}
# Get number of entries.
ncat = stnsymbols (ctable, 0)
# Free mapped variables.
call pr_unmap (map)
# Debug ?
#if (clgetb ("debug.iocode")) {
#call eprintf ("io_gcatdat.out: (ctable=%d) (ncat=%d) (nvars=%d)\n")
#call pargi (list)
#call pargi (ncat)
#call pargi (nvars)
#}
#call dg_dcatdat ("from io_gcatdat", ctable, nvars)
call sfree (sp)
end
# IO_GCATOBS - Get catalog observations from a list of files, and store them
# in a multicolumn table. The catalog data will be appended to the last
# columns of the table, so each line will be "complete".
procedure io_gcatobs (list, ctable, ncatvars, getid, logfile, otable, ntable,
nobs)
int list # file list
pointer ctable # catalog table
int ncatvars # number of catalog variables
int getid # match the ids
char logfile[ARB] # output log file
pointer otable # catalog observations table (output)
pointer ntable # name table (output)
int nobs # number of observations (output)
char eoschar
int i, log, fd, nvars, num, col, ip, tp, index
pointer sp, input, line, token, dummy, indices, map, sym
real rval
#bool clgetb()
int fntgfnb(), ctowrd(), ctor(), open(), pr_findmap()
int io_getline(), io_lineid()
pointer stfind(), mct_getrow()
data eoschar /EOS/
begin
# Debug ?
#if (clgetb ("debug.iocode")) {
#call eprintf ("io_gcatobs.in: (list=%d) (ctable=%d) (ncatv=%d)\n")
#call pargi (list)
#call pargi (ctable)
#call pargi (ncatvars)
#}
# Map the observational variables.
call pr_obsmap (map, nvars)
# Allocate the catalog observation table.
call mct_alloc (otable, LEN_CATOBS, nvars + ncatvars, TY_REAL)
# Allocate the star name table.
if (getid == YES)
call mct_alloc (ntable, LEN_CATOBS, SZ_FNAME + 1, TY_CHAR)
else
call mct_alloc (ntable, LEN_CATOBS, 2, TY_CHAR)
# Open the log file.
if (logfile[1] == EOS) {
log = NULL
} else {
iferr (log = open (logfile, APPEND, TEXT_FILE)) {
call erract (EA_WARN)
log = NULL
}
}
# Allocate working space.
call smark (sp)
call salloc (input, SZ_FNAME, TY_CHAR)
call salloc (line, MAX_CONT * SZ_LINE, TY_CHAR)
call salloc (token, SZ_LINE, TY_CHAR)
call salloc (dummy, SZ_LINE, TY_CHAR)
call salloc (indices, nvars, TY_INT)
# Print banner.
if (log != NULL)
call fprintf (log, "\n#UNMATCHED OBJECTS\n\n")
# Read the catalog observations.
nobs = 0
call fntrewb (list)
while (fntgfnb (list, Memc[input], SZ_LINE) != EOF) {
# Try to open the input file.
iferr (fd = open (Memc[input], READ_ONLY, TEXT_FILE)) {
call erract (EA_WARN)
next
}
# Read the file lines.
call io_getline_init ()
while (io_getline (fd, Memc[line], MAX_CONT * SZ_LINE) != EOF) {
# Get line id from first column if there is a catalog to
# match them. Otherwise assume that there is no catalog.
ip = 1
if (getid == YES) {
if (io_lineid (Memc[line], ip, Memc[dummy], Memc[token],
SZ_LINE) == 0)
next
col = 2
} else
col = 1
# Search for this string in the catalog symbol table if
# one is defined. If it's not found skip to the next
# line or observation.
if (ctable != NULL) {
sym = stfind (ctable, Memc[token])
if (sym == NULL) {
if (log != NULL) {
call fprintf (log,
"File: %s Object: %s was unmatched\n")
call pargstr (Memc[input])
call pargstr (Memc[token])
}
next
}
}
# Count the observations.
nobs = nobs + 1
# Add the symbol to the name table.
if (getid == YES) {
call mct_putc (ntable, nobs, 1, eoschar)
call strcpy (Memc[token], Memc[mct_getrow(ntable, nobs)],
SZ_FNAME)
} else
call mct_putc (ntable, nobs, 1, eoschar)
# Scan input colums and get all variable values.
while (ctowrd (Memc[line], ip, Memc[token], SZ_LINE) > 0) {
# Enter variable value into the observation table
# if it was declared in the configuration file.
tp = 1
if (ctor (Memc[token], tp, rval) > 0) {
num = pr_findmap (map, col, Memi[indices], nvars)
do i = 1, num {
index = Memi[indices+i-1]
if (!IS_INDEFI (index))
call mct_putr (otable, nobs, index, rval)
}
}
# Count input columns
col = col + 1
}
# Now append to the current row all the variable values
# from the catalog table for the same line id, if
# matching is enabled.
if (ncatvars > 0) {
if (ctable == NULL) {
do num = 1, ncatvars
call mct_putr (otable, nobs, nvars + num, INDEFR)
} else {
do num = 1, ncatvars {
rval = Memr[P2R(sym+num-1)]
call mct_putr (otable, nobs, nvars + num, rval)
}
}
}
}
# Close file.
call close (fd)
}
if (log != NULL) {
call fprintf (log, "\n")
call close (log)
}
# Free mapped variables.
call pr_unmap (map)
# Debug ?
#if (clgetb ("debug.iocode")) {
#call eprintf ("io_gcatobs.out: (otable=%d) (nobs=%d)\n")
#call pargi (otable)
#call pargi (nobs)
#}
#call dg_dcatobs ("from io_gcatobs", otable)
call sfree (sp)
end
# IO_LOGTIME -- Write a time stamp in the unmatched stars log file.
procedure io_logtime (logfile)
char logfile[ARB] # the name of the log file
int log
pointer sp, timestr
int open()
long clktime()
begin
if (logfile[1] == EOS)
return
iferr (log = open (logfile, APPEND, TEXT_FILE)) {
call erract (EA_WARN)
return
}
call smark (sp)
call salloc (timestr, SZ_TIME, TY_CHAR)
call cnvtime (clktime(0), Memc[timestr], SZ_TIME)
call strupr (Memc[timestr])
call fprintf (log, "\n#%s\n")
call pargstr (Memc[timestr])
call sfree (sp)
call close (log)
end
# IO_TITLE -- Write the equation title to the logfile
procedure io_title (logfile, title, sym)
char logfile[ARB] # the name of the log file
char title # title
int sym # equation symbol
int log
int open()
pointer pr_xgetname()
begin
if (logfile[1] == EOS)
return
iferr (log = open (logfile, APPEND, TEXT_FILE)) {
call erract (EA_WARN)
return
}
call fprintf (log, "%s %s\n\n")
call pargstr (title)
call pargstr (Memc[pr_xgetname(sym)])
call close (log)
end
|