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
|
include <tbset.h>
# TIHEADER -- Routines for retrieving header-stored scalars.
#
# Details such as keyword names and encoding are defined by the
# way task txtable creates the same keywords.
#
#
#
# TIHKI -- Look for keyword and return integer value, or 0 if not found.
# TIHMAX -- Return maximum number of header-stored scalars.
# TIHNSC -- Return actual number of scalars in header.
# TIHROW -- Return original row value stored by txtable task.
# TIHDEC -- Decode column description in header keyword.
#
#
#
# Revision history:
# ----------------
# 20-Jan-97 - Task created (I.Busko)
# 17-Mar-97 - Revised after code review (IB)
# TIHMAX -- Return maximum number of header-stored scalars.
int procedure tihmax (tp)
pointer tp # table pointer
int tihki()
begin
return (tihki (tp, "TCTOTAL"))
end
# TIHROW -- Return original row value (stored by txtable task).
int procedure tihrow (tp)
pointer tp # table pointer
int tihki()
begin
return (tihki (tp, "ORIG_ROW"))
end
# TIHNSC -- Return actual number of scalars in header.
int procedure tihnsc (tp)
pointer tp # table pointer
#--
pointer sp, kwname, kwval
int dtype, parnum
int i, ntot, nscalar
int tihmax()
begin
call smark (sp)
call salloc (kwval, SZ_PARREC, TY_CHAR)
call salloc (kwname, SZ_LINE, TY_CHAR)
nscalar = 0
ntot = tihmax (tp)
do i = 1, ntot {
call sprintf (kwname, SZ_LINE, "TCD_%03d")
call pargi (i)
call tbhfkr (tp, kwname, dtype, kwval, parnum)
if (parnum > 0)
nscalar = nscalar + 1
}
call sfree (sp)
return (nscalar)
end
# TIHDEC -- Decode column description in header keyword. The detailed
# format depends on how task txtable does the encoding.
bool procedure tihdec (tp, kn, colname, colunits, colfmt, datatype, lenfmt)
pointer tp # i: table pointer
int kn # i: keyword number
char colname[ARB] # o: column name
char colunits[ARB] # o: column units
char colfmt[ARB] # o: column print format
int datatype # o: column data type
int lenfmt # o: format lenght
#--
pointer sp, kwname, kwval, dtype
int parnum
bool found
string corrupt "Corrupted header in input table."
int nscan(), strncmp()
bool streq()
begin
call smark (sp)
call salloc (kwval, SZ_PARREC, TY_CHAR)
call salloc (kwname, SZ_LINE, TY_CHAR)
call salloc (dtype, SZ_LINE, TY_CHAR)
# Build column description keyword name.
call sprintf (Memc[kwname], SZ_LINE, "TCD_%03d")
call pargi (kn)
# Look for it.
call tbhfkr (tp, Memc[kwname], datatype, Memc[kwval], parnum)
if (parnum > 0) {
# Found; parse the 5 fields.
call sscan (Memc[kwval])
call gargwrd (colname, SZ_COLNAME)
if (nscan() < 1) call error (1, corrupt)
call gargwrd (colunits, SZ_COLUNITS)
if (nscan() < 1) call error (1, corrupt)
call gargwrd (colfmt, SZ_COLFMT)
if (nscan() < 1) call error (1, corrupt)
call gargwrd (Memc[dtype], SZ_LINE)
if (nscan() < 1) call error (1, corrupt)
call gargi (lenfmt)
if (nscan() < 1) call error (1, corrupt)
# Translate from human-readable encoding to sdas table encoding.
if (streq (colunits, "default"))
call strcpy ("", colunits, SZ_COLUNITS)
if (streq (colfmt, "default"))
call strcpy ("", colfmt, SZ_COLFMT)
if (streq (Memc[dtype], "boolean")) datatype = TY_BOOL
if (streq (Memc[dtype], "short")) datatype = TY_SHORT
if (streq (Memc[dtype], "integer")) datatype = TY_INT
if (streq (Memc[dtype], "long")) datatype = TY_LONG
if (streq (Memc[dtype], "real")) datatype = TY_REAL
if (streq (Memc[dtype], "double")) datatype = TY_DOUBLE
if (strncmp (Memc[dtype], "character_", 10) == 0) {
call sscan (Memc[dtype+10])
call gargi (datatype)
datatype = -datatype
}
found = true
} else
found = false
call sfree (sp)
return (found)
end
# TIHKI -- Look for keyword and return integer value, or 0 if not found.
# Zero is never expected as a valid result because this routine
# is used to retrieve either the maximum number of header-stored
# scalars (zero means no scalars) or the original table row number.
int procedure tihki (tp, keyword)
pointer tp # table pointer
char keyword[ARB] # keyword
#--
pointer sp, kwval
int dtype, parnum, par
int tbhgti()
begin
call smark (sp)
call salloc (kwval, SZ_PARREC, TY_CHAR)
call tbhfkr (tp, keyword, dtype, kwval, parnum)
if (parnum > 0)
par = tbhgti (tp, keyword)
else
par = 0
call sfree (sp)
return (par)
end
|