aboutsummaryrefslogtreecommitdiff
path: root/pkg/tbtables/tbrpt.x
blob: ee74dba8a1222d50fce3a6d17a2a817712a7e5e0 (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
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
include <tbset.h>
include "tbtables.h"
include "tblerr.h"

# Write column values to a row.
#
# Phil Hodge, 28-Dec-1987  Different data types combined into one file.
# Phil Hodge,  5-Feb-1992  Add option for text table type.
# Phil Hodge, 31-Mar-1993  Include short datatype.
# Phil Hodge,  4-Nov-1993  Include check on row number > 0.
# Phil Hodge,  3-Apr-1995  Set TB_MODIFIED to true.
# Phil Hodge, 23-Jun-1995  Modify for FITS tables.
# Phil Hodge,  3-Mar-1998  Call tbswer1, to allow for row selector.

# tbrptd -- putrow double
# Write column values to a row.  This is for data type double.

procedure tbrptd (tp, cp, buffer, numcols, selrow)

pointer tp			# i: pointer to table descriptor
pointer cp[ARB]			# i: array of pointers to column descriptors
double	buffer[ARB]		# i: array of values to be put into table
int	numcols			# i: number of columns
int	selrow			# i: row number (or selected row number)
#--
int	rownum			# actual row number
int	k			# loop index for column number
errchk	tbswer1, tbxrpd, tbyrpd, tbzptd, tbfapd

begin
	if (TB_READONLY(tp))
	    call error (ER_TBREADONLY, "can't write to table; it's readonly")

	# If we're writing beyond EOF, write extra rows and update TB_NROWS.
	# (But note use of tbswer1, especially for row-ordered table.)
	call tbswer1 (tp, selrow, rownum)

	if (TB_TYPE(tp) == TBL_TYPE_S_ROW)
	    call tbxrpd (tp, cp, buffer, numcols, rownum)
	else if (TB_TYPE(tp) == TBL_TYPE_S_COL)
	    call tbyrpd (tp, cp, buffer, numcols, rownum)
	else if (TB_TYPE(tp) == TBL_TYPE_TEXT)
	    do k = 1, numcols
		call tbzptd (tp, cp[k], rownum, buffer[k])
	else if (TB_TYPE(tp) == TBL_TYPE_FITS)
	    do k = 1, numcols
		call tbfapd (tp, cp[k], rownum, buffer[k], 1, 1)
	else
	    call error (ER_TBCORRUPTED, "tbrptd:  table type is messed up")

	TB_MODIFIED(tp) = true
end


# tbrptr -- putrow real
# Write column values to a row.  This is for data type real.

procedure tbrptr (tp, cp, buffer, numcols, selrow)

pointer tp			# i: pointer to table descriptor
pointer cp[ARB]			# i: array of pointers to column descriptors
real	buffer[ARB]		# i: array of values to be put into table
int	numcols			# i: number of columns
int	selrow			# i: row number (or selected row number)
#--
int	rownum			# actual row number
int	k			# loop index for column number
errchk	tbswer1, tbxrpr, tbyrpr, tbzptr, tbfapr

begin
	if (TB_READONLY(tp))
	    call error (ER_TBREADONLY, "can't write to table; it's readonly")

	# If we're writing beyond EOF, write extra rows and update TB_NROWS.
	call tbswer1 (tp, selrow, rownum)

	if (TB_TYPE(tp) == TBL_TYPE_S_ROW)
	    call tbxrpr (tp, cp, buffer, numcols, rownum)
	else if (TB_TYPE(tp) == TBL_TYPE_S_COL)
	    call tbyrpr (tp, cp, buffer, numcols, rownum)
	else if (TB_TYPE(tp) == TBL_TYPE_TEXT)
	    do k = 1, numcols
		call tbzptr (tp, cp[k], rownum, buffer[k])
	else if (TB_TYPE(tp) == TBL_TYPE_FITS)
	    do k = 1, numcols
		call tbfapr (tp, cp[k], rownum, buffer[k], 1, 1)
	else
	    call error (ER_TBCORRUPTED, "tbrptr:  table type is messed up")

	TB_MODIFIED(tp) = true
end


# tbrpti -- putrow integer
# Write column values to a row.  This is for data type integer.

procedure tbrpti (tp, cp, buffer, numcols, selrow)

pointer tp			# i: pointer to table descriptor
pointer cp[ARB]			# i: array of pointers to column descriptors
int	buffer[ARB]		# i: array of values to be put into table
int	numcols			# i: number of columns
int	selrow			# i: row number (or selected row number)
#--
int	rownum			# actual row number
int	k			# loop index for column number
errchk	tbswer1, tbxrpi, tbyrpi, tbzpti, tbfapi

begin
	if (TB_READONLY(tp))
	    call error (ER_TBREADONLY, "can't write to table; it's readonly")

	# If we're writing beyond EOF, write extra rows and update TB_NROWS.
	call tbswer1 (tp, selrow, rownum)

	if (TB_TYPE(tp) == TBL_TYPE_S_ROW)
	    call tbxrpi (tp, cp, buffer, numcols, rownum)
	else if (TB_TYPE(tp) == TBL_TYPE_S_COL)
	    call tbyrpi (tp, cp, buffer, numcols, rownum)
	else if (TB_TYPE(tp) == TBL_TYPE_TEXT)
	    do k = 1, numcols
		call tbzpti (tp, cp[k], rownum, buffer[k])
	else if (TB_TYPE(tp) == TBL_TYPE_FITS)
	    do k = 1, numcols
		call tbfapi (tp, cp[k], rownum, buffer[k], 1, 1)
	else
	    call error (ER_TBCORRUPTED, "tbrpti:  table type is messed up")

	TB_MODIFIED(tp) = true
end


# tbrpts -- putrow short
# Write column values to a row.  This is for data type short integer.

procedure tbrpts (tp, cp, buffer, numcols, selrow)

pointer tp			# i: pointer to table descriptor
pointer cp[ARB]			# i: array of pointers to column descriptors
short	buffer[ARB]		# i: array of values to be put into table
int	numcols			# i: number of columns
int	selrow			# i: row number (or selected row number)
#--
int	rownum			# actual row number
int	k			# loop index for column number
errchk	tbswer1, tbxrps, tbyrps, tbzpts, tbfaps

begin
	if (TB_READONLY(tp))
	    call error (ER_TBREADONLY, "can't write to table; it's readonly")

	# If we're writing beyond EOF, write extra rows and update TB_NROWS.
	call tbswer1 (tp, selrow, rownum)

	if (TB_TYPE(tp) == TBL_TYPE_S_ROW)
	    call tbxrps (tp, cp, buffer, numcols, rownum)
	else if (TB_TYPE(tp) == TBL_TYPE_S_COL)
	    call tbyrps (tp, cp, buffer, numcols, rownum)
	else if (TB_TYPE(tp) == TBL_TYPE_TEXT)
	    do k = 1, numcols
		call tbzpts (tp, cp[k], rownum, buffer[k])
	else if (TB_TYPE(tp) == TBL_TYPE_FITS)
	    do k = 1, numcols
		call tbfaps (tp, cp[k], rownum, buffer[k], 1, 1)
	else
	    call error (ER_TBCORRUPTED, "tbrpts:  table type is messed up")

	TB_MODIFIED(tp) = true
end


# tbrptb -- putrow Boolean
# This is for data type Boolean.

procedure tbrptb (tp, cp, buffer, numcols, selrow)

pointer tp			# i: pointer to table descriptor
pointer cp[ARB]			# i: array of pointers to column descriptors
bool	buffer[ARB]		# i: array of values to be put into table
int	numcols			# i: number of columns
int	selrow			# i: row number (or selected row number)
#--
int	rownum			# actual row number
int	k			# loop index for column number
errchk	tbswer1, tbxrpb, tbyrpb, tbzptb, tbfapb

begin
	if (TB_READONLY(tp))
	    call error (ER_TBREADONLY, "can't write to table; it's readonly")

	# If we're writing beyond EOF, write extra rows and update TB_NROWS.
	call tbswer1 (tp, selrow, rownum)

	if (TB_TYPE(tp) == TBL_TYPE_S_ROW)
	    call tbxrpb (tp, cp, buffer, numcols, rownum)
	else if (TB_TYPE(tp) == TBL_TYPE_S_COL)
	    call tbyrpb (tp, cp, buffer, numcols, rownum)
	else if (TB_TYPE(tp) == TBL_TYPE_TEXT)
	    do k = 1, numcols
		call tbzptb (tp, cp[k], rownum, buffer[k])
	else if (TB_TYPE(tp) == TBL_TYPE_FITS)
	    do k = 1, numcols
		call tbfapb (tp, cp[k], rownum, buffer[k], 1, 1)
	else
	    call error (ER_TBCORRUPTED, "tbrptb:  table type is messed up")

	TB_MODIFIED(tp) = true
end


# tbrptt -- putrow text
# Write column values to a row.  This is for character strings.

procedure tbrptt (tp, cp, buffer, lenstr, numcols, selrow)

pointer tp			# i: pointer to table descriptor
pointer cp[ARB]			# i: array of pointers to column descriptors
char	buffer[lenstr,ARB]	# i: array of values to be put into table
int	lenstr			# i: length of each string in array buffer
int	numcols			# i: number of columns
int	selrow			# i: row number (or selected row number)
#--
int	rownum			# actual row number
int	k			# loop index for column number
errchk	tbswer1, tbxrpt, tbyrpt, tbzptt, tbfapt

begin
	if (TB_READONLY(tp))
	    call error (ER_TBREADONLY, "can't write to table; it's readonly")

	# If we're writing beyond EOF, write extra rows and update TB_NROWS.
	call tbswer1 (tp, selrow, rownum)

	if (TB_TYPE(tp) == TBL_TYPE_S_ROW)
	    call tbxrpt (tp, cp, buffer, lenstr, numcols, rownum)
	else if (TB_TYPE(tp) == TBL_TYPE_S_COL)
	    call tbyrpt (tp, cp, buffer, lenstr, numcols, rownum)
	else if (TB_TYPE(tp) == TBL_TYPE_TEXT)
	    do k = 1, numcols
		call tbzptt (tp, cp[k], rownum, buffer[1,k])
	else if (TB_TYPE(tp) == TBL_TYPE_FITS)
	    do k = 1, numcols
		call tbfapt (tp, cp[k], rownum, buffer[1,k], lenstr, 1, 1)
	else
	    call error (ER_TBCORRUPTED, "tbrptt:  table type is messed up")

	TB_MODIFIED(tp) = true
end