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
|
.help prmap
Column/variable mapping.
These procedures map input column numbers, specified in the configuration
file, with variable numbers that are used to index information in memory
tables. Variable numbers are assigned internally by the parser.
.sp
The main goal of these routines is to provide a fast way of converting from
column number to a variable number, if any, since this kind of operation is
performed by the i/o routines for eavery column in all lines in each input
file.
.sp
First the calling program should map columns with variables in the catalog
or observation section of the configuration file, by using either pr_obsmap()
or pr_catmap(). Once the mapping is built the corresponding variable number
for a given column can be obtained with pr_findmap(). All memory allocated
by these procedures is free by calling pr_unmap().
.nf
Main entry points:
pr_obsmap (table, nobs) Build observational variables map
pr_catmap (table, ncat) Build catalog variables map
int pr_findmap (table, col, nums, max_nums) Find var numbers for given column
int pr_findmap1 (table, col) Find first var number for given column
pr_unmap (table) Free space of mapped variables
Low level entry points:
pr_inmap (table, nvars, type) Map observational/catalog var.
.endhelp
include "../lib/parser.h"
include "../lib/prdefs.h"
# Table structure
define LEN_TABLE 5 # fixed section length
define TABLE_MIN Memi[$1+0] # minimum column number
define TABLE_MAX Memi[$1+1] # maximum column number
define TABLE_NVARS Memi[$1+2] # number of variables
define TABLE_PCOLS Memi[$1+3] # pointer to column indices
define TABLE_PNCOLS Memi[$1+4] # pointer to column indices count
# PR_OBSTAB -- Map program observational input variables.
procedure pr_obsmap (table, nobs)
pointer table # table pointer (output)
int nobs # number of observational variables (output)
begin
# Tabulate the observational variables.
call pr_inmap (table, nobs, PTY_OBSVAR)
end
# PR_CATTAB -- Map catalog star input variables.
procedure pr_catmap (table, ncat)
pointer table # table pointer (output)
int ncat # number of catalog variables (output)
begin
# Tabulate the catalog variables.
call pr_inmap (table, ncat, PTY_CATVAR)
end
# PR_INMAP -- Map input variables from the sequential variable table, and
# build a table with this mapping. A pointer to the map table is returned,
# for future use by pr_findmap().
procedure pr_inmap (table, nvars, type)
pointer table # table pointer (output)
int nvars # number of variables (output)
int type # symbol type
int i, mincol, maxcol, sym, col
pointer pcols, pncols, colptr
int pr_geti(), pr_gsym(), pr_gsymi()
begin
# Get the sequential table pointer for the symbol type, and the
# maximum and minimum number of columns
if (type == PTY_OBSVAR) {
nvars = pr_geti (NOBSVARS)
mincol = pr_geti (MINOBSCOL)
maxcol = pr_geti (MAXOBSCOL)
} else if (type == PTY_CATVAR) {
nvars = pr_geti (NCATVARS)
mincol = pr_geti (MINCATCOL)
maxcol = pr_geti (MAXCATCOL)
} else
call error (0, "pr_inmap: Illegal symbol type")
# Allocate the basic table structure.
call malloc (table, LEN_TABLE, TY_STRUCT)
TABLE_MIN (table) = mincol
TABLE_MAX (table) = maxcol
TABLE_NVARS (table) = nvars
# Initialize.
call malloc (pcols, maxcol * nvars, TY_INT)
call amovki (INDEFI, Memi[pcols], maxcol * nvars)
call calloc (pncols, maxcol, TY_INT)
# Traverse symbols and store variable number at the corresponding
# table location indexed by column number. There may be more than
# one symbol per column number.
do i = 1, nvars {
sym = pr_gsym (i, type)
col = pr_gsymi (sym, PINPCOL)
colptr = pcols + (col - 1) * nvars + Memi[pncols+col-1]
Memi[colptr] = pr_gsymi (sym, PSYMNUM)
Memi[pncols+col-1] = Memi[pncols+col-1] + 1
}
TABLE_PCOLS(table) = pcols
TABLE_PNCOLS(table) = pncols
end
# PR_FINDMAP -- Find the list of symbol numbers for a given input column.
int procedure pr_findmap (table, col, indices, max_nindices)
pointer table # table pointer
int col # input column
int indices[ARB] # output array of indices
int max_nindices # maximum permitted number of indices
int nvars, nindices
pointer colptr
begin
# Check pointer.
if (table == NULL)
call error (0, "pr_findmap: Null table pointer")
# Check the table size.
nvars = TABLE_NVARS(table)
if (max_nindices < nvars)
call error (0, "pr_findmap: The output index array is too short")
# Look for variable number.
if (col < TABLE_MIN (table) || col > TABLE_MAX (table)) {
nindices = 0
call amovki (INDEFI, indices, nvars)
} else {
nindices = Memi[TABLE_PNCOLS(table)+col-1]
colptr = TABLE_PCOLS(table) + (col - 1) * nvars
call amovi (Memi[colptr], indices, nindices)
}
return (nindices)
end
# PR_FINDMAP1 -- Find the symbol number for a given input column.
int procedure pr_findmap1 (table, col)
pointer table # table pointer
int col # input column
begin
# Check pointer.
if (table == NULL)
call error (0, "pr_findmap: Null table pointer")
# Look for variable number.
if (col < TABLE_MIN (table) || col > TABLE_MAX (table))
return (INDEFI)
else
return (Memi[TABLE_PCOLS(table)+(col-1)*TABLE_NVARS(table)])
end
# PR_UNMAP -- Free space of mapped variables.
procedure pr_unmap (table)
pointer table # table pointer
begin
# Check pointer.
if (table == NULL)
call error (0, "pr_unmap: Null table pointer")
# Free pointer table.
call mfree (TABLE_PCOLS(table), TY_INT)
call mfree (TABLE_PNCOLS(table), TY_INT)
# Free table structure.
call mfree (table, TY_INT)
end
|