aboutsummaryrefslogtreecommitdiff
path: root/pkg/tbtables/tbzpt.x
blob: 982d59005efd94ed8d3d89e08460c6b21d5b88e2 (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
include "tbtables.h"

# tbzpt[tbirds] -- put a single element
# This procedure puts a single element into an internal buffer corresponding
# to a value in a text file.
#
# Phil Hodge, 14-Jan-1992  Subroutines created.
# Phil Hodge, 31-Mar-1993  Include short datatype.
# Phil Hodge, 12-Aug-1993  Use ctol instead of ctoi to allow leading "+" sign.
# Phil Hodge,  4-Mar-1998  Remove calls to tbtwer.

procedure tbzptb (tp, cp, rownum, buffer)

pointer tp			# i: pointer to table descriptor
pointer cp			# i: pointer to column descriptor
int	rownum			# i: row number
bool	buffer			# i: value to be put
#--
int	lenstr			# length of a string table element
int	ip			# offset to a string in Memc

begin
	if (COL_DTYPE(cp) == TBL_TY_DOUBLE) {
	    if (buffer)
		Memd[COL_OFFSET(cp) + rownum - 1] = YES
	    else
		Memd[COL_OFFSET(cp) + rownum - 1] = NO

	} else if (COL_DTYPE(cp) == TBL_TY_INT) {
	    if (buffer)
		Memi[COL_OFFSET(cp) + rownum - 1] = YES
	    else
		Memi[COL_OFFSET(cp) + rownum - 1] = NO

	} else {				# string
	    lenstr = -COL_DTYPE(cp)		# not including EOS
	    ip = (rownum - 1) * (lenstr + 1)	# including EOS
	    if (buffer)
		call strcpy ("yes", Memc[COL_OFFSET(cp) + ip], lenstr)
	    else
		call strcpy ("no", Memc[COL_OFFSET(cp) + ip], lenstr)
	}
end

procedure tbzptd (tp, cp, rownum, buffer)

pointer tp			# i: pointer to table descriptor
pointer cp			# i: pointer to column descriptor
int	rownum			# i: row number
double	buffer			# i: value to be put
#--
char	cbuf[SZ_FNAME]		# buffer for character elements
int	lenstr			# length of a string table element
int	ip			# offset to a string in Memc

begin
	if (COL_DTYPE(cp) == TBL_TY_DOUBLE) {
	    Memd[COL_OFFSET(cp) + rownum - 1] = buffer

	} else if (COL_DTYPE(cp) == TBL_TY_INT) {
	    if (IS_INDEFD(buffer))
		Memi[COL_OFFSET(cp) + rownum - 1] = INDEFI
	    else
		Memi[COL_OFFSET(cp) + rownum - 1] = nint (buffer)

	} else {				# string
	    if (IS_INDEFD(buffer)) {
		call strcpy ("INDEF", cbuf, SZ_FNAME)
	    } else {
		call sprintf (cbuf, SZ_FNAME, "%.16g")
		    call pargd (buffer)
	    }
	    lenstr = -COL_DTYPE(cp)		# not including EOS
	    ip = (rownum - 1) * (lenstr + 1)	# including EOS
	    call strcpy (cbuf, Memc[COL_OFFSET(cp) + ip], lenstr)
	}
end

procedure tbzptr (tp, cp, rownum, buffer)

pointer tp			# i: pointer to table descriptor
pointer cp			# i: pointer to column descriptor
int	rownum			# i: row number
real	buffer			# i: value to be put
#--
char	cbuf[SZ_FNAME]		# buffer for character elements
int	lenstr			# length of a string table element
int	ip			# offset to a string in Memc

begin
	if (COL_DTYPE(cp) == TBL_TY_DOUBLE) {
	    if (IS_INDEF(buffer))
		Memd[COL_OFFSET(cp) + rownum - 1] = INDEFD
	    else
		Memd[COL_OFFSET(cp) + rownum - 1] = buffer

	} else if (COL_DTYPE(cp) == TBL_TY_INT) {
	    if (IS_INDEF(buffer))
		Memi[COL_OFFSET(cp) + rownum - 1] = INDEFI
	    else
		Memi[COL_OFFSET(cp) + rownum - 1] = nint (buffer)

	} else {				# string
	    if (IS_INDEF(buffer)) {
		call strcpy ("INDEF", cbuf, SZ_FNAME)
	    } else {
		call sprintf (cbuf, SZ_FNAME, "%.6g")
		    call pargr (buffer)
	    }
	    lenstr = -COL_DTYPE(cp)		# not including EOS
	    ip = (rownum - 1) * (lenstr + 1)	# including EOS
	    call strcpy (cbuf, Memc[COL_OFFSET(cp) + ip], lenstr)
	}
end

procedure tbzpti (tp, cp, rownum, buffer)

pointer tp			# i: pointer to table descriptor
pointer cp			# i: pointer to column descriptor
int	rownum			# i: row number
int	buffer			# i: value to be put
#--
char	cbuf[SZ_FNAME]		# buffer for character elements
int	lenstr			# length of a string table element
int	ip			# offset to a string in Memc

begin
	if (COL_DTYPE(cp) == TBL_TY_DOUBLE) {
	    if (IS_INDEFI(buffer))
		Memd[COL_OFFSET(cp) + rownum - 1] = INDEFD
	    else
		Memd[COL_OFFSET(cp) + rownum - 1] = buffer

	} else if (COL_DTYPE(cp) == TBL_TY_INT) {
	    Memi[COL_OFFSET(cp) + rownum - 1] = buffer

	} else {				# string
	    if (IS_INDEFI(buffer)) {
		call strcpy ("INDEF", cbuf, SZ_FNAME)
	    } else {
		call sprintf (cbuf, SZ_FNAME, "%d")
		    call pargi (buffer)
	    }
	    lenstr = -COL_DTYPE(cp)		# not including EOS
	    ip = (rownum - 1) * (lenstr + 1)	# including EOS
	    call strcpy (cbuf, Memc[COL_OFFSET(cp) + ip], lenstr)
	}
end

procedure tbzpts (tp, cp, rownum, buffer)

pointer tp			# i: pointer to table descriptor
pointer cp			# i: pointer to column descriptor
int	rownum			# i: row number
short	buffer			# i: value to be put
#--
char	cbuf[SZ_FNAME]		# buffer for character elements
int	lenstr			# length of a string table element
int	ip			# offset to a string in Memc

begin
	if (COL_DTYPE(cp) == TBL_TY_DOUBLE) {
	    if (IS_INDEFS(buffer))
		Memd[COL_OFFSET(cp) + rownum - 1] = INDEFD
	    else
		Memd[COL_OFFSET(cp) + rownum - 1] = buffer

	} else if (COL_DTYPE(cp) == TBL_TY_INT) {
	    if (IS_INDEFS(buffer))
		Memi[COL_OFFSET(cp) + rownum - 1] = INDEFI
	    else
		Memi[COL_OFFSET(cp) + rownum - 1] = buffer

	} else {				# string
	    if (IS_INDEFS(buffer)) {
		call strcpy ("INDEF", cbuf, SZ_FNAME)
	    } else {
		call sprintf (cbuf, SZ_FNAME, "%d")
		    call pargs (buffer)
	    }
	    lenstr = -COL_DTYPE(cp)		# not including EOS
	    ip = (rownum - 1) * (lenstr + 1)	# including EOS
	    call strcpy (cbuf, Memc[COL_OFFSET(cp) + ip], lenstr)
	}
end

procedure tbzptt (tp, cp, rownum, buffer)

pointer tp			# i: pointer to table descriptor
pointer cp			# i: pointer to column descriptor
int	rownum			# i: row number
char	buffer[ARB]		# i: value to be put
#--
int	lenstr			# length of a string table element
int	ip			# offset to a string in Memc
long	lval			# so we can use ctol
int	ctod(), ctol()

begin
	if (COL_DTYPE(cp) == TBL_TY_DOUBLE) {
	    ip = 1
	    if (ctod (buffer, ip, Memd[COL_OFFSET(cp) + rownum - 1]) < 1)
		Memd[COL_OFFSET(cp) + rownum - 1] = INDEFD

	} else if (COL_DTYPE(cp) == TBL_TY_INT) {
	    ip = 1
	    if (ctol (buffer, ip, lval) > 0)
		Memi[COL_OFFSET(cp) + rownum - 1] = lval
	    else
		Memi[COL_OFFSET(cp) + rownum - 1] = INDEFI
#***	    if (ctoi (buffer, ip, Memi[COL_OFFSET(cp) + rownum - 1]) < 1)
#***		Memi[COL_OFFSET(cp) + rownum - 1] = INDEFI

	} else {				# string
	    lenstr = -COL_DTYPE(cp)		# not including EOS
	    ip = (rownum - 1) * (lenstr + 1)	# including EOS
	    call strcpy (buffer, Memc[COL_OFFSET(cp) + ip], lenstr)
	}
end