-
Notifications
You must be signed in to change notification settings - Fork 1
/
dauscatgath.c
404 lines (321 loc) · 11.9 KB
/
dauscatgath.c
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
#if HAVE_CONFIG_H
# include <config.h>
#endif
/*+DAUSCATGATH.C-*/
/* Include files */
#include "ems.h" /* EMS error reporting routines */
#include "hds1.h" /* Global definitions for HDS */
#include "rec.h" /* Public rec_ definitions */
#include "str.h" /* Character string import/export macros */
#include "dat1.h" /* Internal dat_ definitions */
#include "dat_err.h" /* DAT__ error code definitions */
/* Control Blocks */
int
dau_gather_data( int bad, struct LCP_DATA *data, int *nbad )
/*+
* DAU_GATHER_DATA - Gather discontiguous data
*
* This routine gathers discontiguous data from a sliced primitive object.
* The object slice is mapped from 'corner to corner' if the process can
* accommodate the increase in virtual memory space, otherwise the data
* must be read in chunks.
*
* Calling sequence:
*
* DAU_GATHER_DATA(DATA)
*
* DATA is the address of the data part of the Locator Control Packet.
*
* Routine value:
*
* DAT__OK if successful.
*/
{
struct PDD app;
struct PDD obj;
HDS_PTYPE *axis;
HDS_PTYPE (*dbt)[2];
struct ODL odl;
HDS_PTYPE stride[DAT__MXSLICE];
HDS_PTYPE mult[DAT__MXSLICE];
int naxes;
int nval;
int nchunk;
int nplane;
INT_BIG lower;
INT_BIG upper;
INT_BIG len;
INT_BIG pos;
INT_BIG off=0;
unsigned char *dom;
int bitty;
int count;
int i;
int n;
int nbad1;
int temp_status;
*nbad = 0;
/* Copy the object data and application data attributes descriptors. */
obj = data->obj;
app = data->app;
/* Read the Object Descriptor Label and associate the axes vector. */
_invoke(dat1_get_odl(&data->han, &odl));
axis = odl.axis;
naxes = odl.naxes;
/* Calculate the object data strides. */
stride[0] = obj.length;
for (i=1; i<naxes; i++)
stride[i] = stride[i-1] * axis[i-1];
/* Associate the Dimension Bounds Table and calculate the bounds multipliers. */
dbt = data->bounds;
for (i=0; i<naxes; i++)
mult[i] = dbt[i][UPPER] - dbt[i][LOWER] + 1;
/* Calculate the # of values in a chunk and the # of chunks in a plane. */
nval = mult[0];
nchunk = 1;
if (mult[0] == axis[0])
nval *= mult[1];
else
nchunk = mult[1];
/* Determine the # of planes in the slice. */
nplane = (naxes == 3) ? mult[2] : 1;
/* Save the lower offset and calculate the upper offset for a 2-D object.
(Adjust the upper offset if the object is 3-D). */
lower = data->offset;
upper = dbt[0][UPPER] - 1 + axis[0]*(dbt[1][UPPER]-1);
if (naxes == 3)
upper += axis[0] * axis[1] * (dbt[2][UPPER]-1);
/* Change the offset values to bytes and calculate the # of bytes between
them. */
lower *= obj.length;
upper = ( upper * obj.length ) + obj.length - 1; /* RFWS changed 22/12/92 */
/* because only the first*/
/* byte of the last */
/* element was being */
/* used. */
len = upper - lower + 1;
/* Determine the # of pages available for virtual memory expansion and
whether the object data has to be mapped in chunks. */
bitty = (len > 512 * hds_gl_nblocks);
/* Map all the object data if it can be done. */
if (!bitty)
_invoke(rec_locate_data(&data->han, len, lower, 'R', &dom));
/* Initialise the count of values remaining and scan through the planes of
the slice. */
pos = 0;
count = data->size;
for (i=1; i<=nplane; i++)
/* Travel through a plane, chunk by chunk. */
{
for (n=0; n<nchunk; n++)
/* Calculate the # of values remaining in the chunk and the offset
into the domain. Assume the data was mapped in one go and save
the address accordingly. */
{
nval = _min(nval, count);
obj.body = dom + pos + (INT_BIG)stride[ 1 ] * (INT_BIG)n;
/* If the data could not be mapped in one go, then map this chunk. Ensure */
/* that this occurs even if the global status is set to DAT__CONER because */
/* of a previous conversion error. */
if (bitty)
{
len= nval * obj.length;
off = lower + pos + (INT_BIG)stride[ 1 ] * (INT_BIG)n;
temp_status = hds_gl_status;
if ( hds_gl_status == DAT__CONER )
hds_gl_status = DAT__OK;
_invoke( rec_locate_data( &data->han, len, off, 'R', &dom ) );
if ( _ok( hds_gl_status ) )
hds_gl_status = temp_status;
obj.body = dom;
}
/* Translate the data in the chunk and accumulate the count of conversion */
/* errors. */
dat1_cvt( bad, nval, &obj, &app, &nbad1 );
*nbad += nbad1;
/* Unmap the chunk if necessary. */
if ( bitty )
{
temp_status = hds_gl_status;
if ( hds_gl_status == DAT__CONER )
hds_gl_status = DAT__OK;
rec_release_data( &data->han, len, off, 'R', &dom );
if ( _ok( hds_gl_status ) ) hds_gl_status = temp_status;
}
/* Adjust the remaining count and exit if all done. Otherwise,
modify the applications data pointer accordingly. */
count -= nval;
if (count <= 0)
break;
app.body += app.length * nval;
}
/* Increment the position for the next plane. */
pos += stride[2];
}
/* Ditch the frame if mapped in one go. */
if ( !bitty )
{
temp_status = hds_gl_status;
if ( hds_gl_status == DAT__CONER )
hds_gl_status = DAT__OK;
rec_release_data( &data->han, len, lower, 'R', &dom );
if ( _ok( hds_gl_status ) )
hds_gl_status = temp_status;
}
return hds_gl_status;
}
int
dau_scatter_data( int bad, struct LCP_DATA *data, int *nbad )
/*+
* DAU_SCATTER_DATA - Scatter discontiguous data
*
* This routine scatters discontiguous data to a sliced primitive object.
* The object slice is mapped from 'corner to corner' if the process can
* accommodate the increase in virtual memory space, otherwise the data
* must be written in chunks.
*
* Calling sequence:
*
* DAU_SCATTER_DATA(DATA)
*
* DATA is the address of the data part of the Locator Control Packet.
*
* Routine value:
*
* DAT__OK if successful.
*/
{
struct PDD app;
struct PDD obj;
HDS_PTYPE *axis;
HDS_PTYPE (*dbt)[2];
struct ODL odl;
HDS_PTYPE stride[DAT__MXSLICE];
HDS_PTYPE mult[DAT__MXSLICE];
int naxes;
int nval;
int nchunk;
int nplane;
INT_BIG lower;
INT_BIG upper;
INT_BIG len;
INT_BIG pos;
INT_BIG off=0;
unsigned char *dom;
int bitty;
int count;
int i;
int n;
int nbad1;
int temp_status;
*nbad = 0;
/* Copy the object data and application data attributes descriptors. */
obj = data->obj;
app = data->app;
/* Read the Object Descriptor Label and associate the axes vector. */
_invoke(dat1_get_odl(&data->han, &odl));
axis = odl.axis;
naxes = odl.naxes;
/* Calculate the object data strides. */
stride[0] = obj.length;
for (i=1; i<naxes; i++)
stride[i] = stride[i-1] * axis[i-1];
/* Associate the Dimension Bounds Table and calculate the bounds multipliers. */
dbt = data->bounds;
for (i=0; i<naxes; i++)
mult[i] = dbt[i][UPPER] - dbt[i][LOWER] + 1;
/* Calculate the # of values in a chunk and the # of chunks in a plane. */
nval = mult[0];
nchunk = 1;
if (mult[0] == axis[0])
nval *= mult[1];
else
nchunk = mult[1];
/* Determine the # of planes in the slice. */
nplane = (naxes == 3) ? mult[2] : 1;
/* Save the lower offset and calculate the upper offset for a 2-D object.
(Adjust the upper offset if the object is 3-D). */
lower = data->offset;
upper = dbt[0][UPPER] - 1 + axis[0]*(dbt[1][UPPER]-1);
if (naxes == 3)
upper += axis[0] * axis[1] * (dbt[2][UPPER]-1);
/* Change the offset values to bytes and calculate the # of bytes between
them. */
lower *= obj.length;
upper = ( upper * obj.length ) + obj.length - 1; /* RFWS changed 22/12/92 */
/* because only the first*/
/* byte of the last */
/* element was being */
/* used. */
len = upper - lower + 1;
/* Determine the # of pages available for virtual memory expansion and
whether the object data has to be mapped in chunks. */
bitty = (len > 512 * hds_gl_nblocks);
/* Map all the object data if it can be done. */
if (!bitty)
_invoke(rec_locate_data(&data->han, len, lower, 'U', &dom));
/* Initialise the count of values remaining and scan through the planes of
the slice. */
pos = 0;
count = data->size;
for (i=1; i<=nplane; i++)
/* Travel through a plane, chunk by chunk. */
{
for (n=0; n<nchunk; n++)
/* Calculate the # of values remaining in the chunk and the offset
into the domain. Assume the data was mapped in one go and save
the address accordingly. */
{
nval = _min(nval, count);
obj.body = dom + pos + (INT_BIG)stride[ 1 ] * (INT_BIG)n;
/* If the data could not be mapped in one go, then map this chunk. Ensure */
/* that this occurs even if the global status is set to DAT__CONER because */
/* of a previous conversion error. */
if ( bitty )
{
len = nval * obj.length;
off = lower + pos + (INT_BIG)stride[ 1 ] * (INT_BIG)n;
temp_status = hds_gl_status;
if ( hds_gl_status == DAT__CONER )
hds_gl_status = DAT__OK;
_invoke( rec_locate_data( &data->han, len, off, 'W', &dom ) );
if ( _ok( hds_gl_status ) )
hds_gl_status = temp_status;
obj.body = dom;
}
/* Translate the data in the chunk, accumulating the count of conversion */
/* errors. */
dat1_cvt( bad, nval, &app, &obj, &nbad1 );
*nbad += nbad1;
/* Unmap the chunk if necessary. */
if ( bitty )
{
temp_status = hds_gl_status;
if ( hds_gl_status == DAT__CONER )
hds_gl_status = DAT__OK;
rec_release_data( &data->han, len, off, 'W', &dom );
if ( _ok( hds_gl_status ) )
hds_gl_status = temp_status;
}
/* Adjust the remaining count and exit if all done. Otherwise,
modify the applications data pointer accordingly. */
count -= nval;
if (count <= 0)
break;
app.body += app.length * nval;
}
/* Increment the position for the next plane. */
pos += stride[2];
}
/* Ditch the frame if mapped in one go. */
if ( !bitty )
{
temp_status = hds_gl_status;
if ( hds_gl_status == DAT__CONER )
hds_gl_status = DAT__OK;
rec_release_data( &data->han, len, lower, 'W', &dom );
if ( _ok( hds_gl_status ) )
hds_gl_status = temp_status;
}
return hds_gl_status;
}