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
|
include "../lib/io.h"
# IO_GOBS - Get next observation from a file, either from data in the catalog
# or not. For data found in the catalog return its catalog values at the end of
# the array. Otherwise append INDEF values. If catalog matching is not being
# used don't append anything. Return the number of variables read, or EOF.
int procedure io_gobs (fd, ctable, map, type, vars, nvars, getid, ulineid,
clineid, maxch)
int fd # file descriptor
pointer ctable # catalog table
pointer map # mapped columns
int type # type of object to be processed
real vars[nvars] # observations (output)
int nvars # number of variables
int getid # get the object id
char ulineid[maxch] # user's line identifier (output)
char clineid[maxch] # compresses line identifier (output)
int maxch # max number of chars.
int i, num, col, ip, tp, index, nread
pointer sp, line, token, indices, sym
real rval
#bool clgetb()
int ctowrd(), ctor(), pr_findmap(), io_getline(), io_lineid()
pointer stfind()
begin
# Debug ?
#if (clgetb ("debug.iocode")) {
#call eprintf ("io_obs.in: (fd=%d) (ctable=%d) (map=%d) ")
#call pargi (fd)
#call pargi (ctable)
#call pargi (map)
#call eprintf ("(nvars=%d) (maxch=%d)\n")
#call pargi (nvars)
#call pargi (maxch)
#}
# Allocate working space.
call smark (sp)
call salloc (line, MAX_CONT * SZ_LINE, TY_CHAR)
call salloc (token, SZ_LINE, TY_CHAR)
call salloc (indices, nvars, TY_INT)
# Loop reading lines until the next desired data is found.
# Return EOF if there are no more lines, and the number of
# variables read otherwise.
repeat {
# Get next line from file
if (io_getline (fd, Memc[line], MAX_CONT * SZ_LINE) == EOF) {
call sfree (sp)
return (EOF)
}
#if (clgetb ("debug.iocode")) {
#call eprintf ("[%s]\n")
#call pargstr (Memc[line])
#}
# Get the line id if catalog matching is being used.
ip = 1
if (getid == YES) {
if (io_lineid (Memc[line], ip, ulineid, clineid, maxch) == 0)
next
col = 2
} else {
col = 1
ulineid[1] = EOS
}
# Break the loop when the appropiate data type is found.
# This is always the case when all the data type is selected,
# or no catalog matching is being used.
if (ctable == NULL) {
sym = NULL
break
} else {
sym = stfind (ctable, clineid)
if (type == TYPE_ALL)
break
else if ((type == TYPE_PROGRAM) && (sym == NULL))
break
else if ((type == TYPE_STANDARDS) && (sym != NULL))
break
}
}
# Initialize the variables array to INDEF.
call amovkr (INDEFR, vars, nvars)
# Scan input colums and get all observational variable values.
nread = 0
while (ctowrd (Memc[line], ip, Memc[token], SZ_LINE) > 0) {
# Enter variable 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))
next
if (index > nvars)
call error (0, "Array index out of bounds (io_gobs)")
vars[index] = rval
nread = max (nread, index)
}
} else if (col == 1 && getid == YES)
call strcpy (Memc[token], ulineid, SZ_LINE)
# Count the input columns.
col = col + 1
}
# If catalog matching is being used append to the output array
# all the catalog values from the catalog table. If these values
# are not defined (not found in the catalog) append INDEF values.
if (sym != NULL) {
do num = nread + 1, nvars
vars[num] = Memr[P2R(sym+num-nread-1)]
nread = nvars
}
# Debug ?
#if (clgetb ("debug.iocode")) {
#call eprintf ("io_obs.out: (nread=%d)")
#call pargi (nread)
#do ip = 1, nread {
#call eprintf (" (%g)")
#call pargr (vars[ip])
#}
#call eprintf (" (ulineid=%s) (clineid=%s)\n")
#call pargstr (ulineid)
#call pargstr (clineid)
#}
call sfree (sp)
# Return the number of variables read.
return (nread)
end
|