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
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <mii.h>
# MII.X -- This is a stand-alone port of the miiread/miiwrite routines from
# etc/osb, modified for IMFORT to use bfio.
#
# status = i_miirdi (fp, spp, maxelem)
# status = i_miirdl (fp, spp, maxelem)
# status = i_miirdr (fp, spp, maxelem)
#
# status = i_miiwri (fp, spp, nelem)
# status = i_miiwrl (fp, spp, nelem)
# status = i_miiwrr (fp, spp, nelem)
#
# status = i_miirdc (fp, spp, maxchars)
# status = i_miiwrc (fp, spp, nchars)
# MIIRDI -- Read a block of data stored externally in MII integer format.
# Data is returned in the format of the local host machine.
int procedure i_miirdi (fp, spp, maxelem)
pointer fp #I input file
int spp[ARB] #O receives data
int maxelem #I max number of data elements to be read
pointer sp, bp
int pksize, nchars, nelem
int miipksize(), miinelem(), bfrseq()
begin
pksize = miipksize (maxelem, MII_INT)
nelem = EOF
if (pksize > maxelem * SZ_INT) {
# Read data into local buffer and unpack into user buffer.
call smark (sp)
call salloc (bp, pksize, TY_CHAR)
nchars = bfrseq (fp, Memc[bp], pksize)
if (nchars != EOF) {
nelem = min (maxelem, miinelem (nchars, MII_INT))
call miiupki (Memc[bp], spp, nelem, TY_INT)
}
call sfree (sp)
} else {
# Read data into user buffer and unpack in place.
nchars = bfrseq (fp, spp, pksize)
if (nchars != EOF) {
nelem = min (maxelem, miinelem (nchars, MII_INT))
call miiupki (spp, spp, nelem, TY_INT)
}
}
return (nelem)
end
# MIIRDL -- Read a block of data stored externally in MII long integer format.
# Data is returned in the format of the local host machine.
int procedure i_miirdl (fp, spp, maxelem)
pointer fp #I input file
long spp[ARB] #O receives data
int maxelem #I max number of data elements to be read
pointer sp, bp
int pksize, nchars, nelem
int miipksize(), miinelem(), bfrseq()
begin
pksize = miipksize (maxelem, MII_LONG)
nelem = EOF
if (pksize > maxelem * SZ_LONG) {
# Read data into local buffer and unpack into user buffer.
call smark (sp)
call salloc (bp, pksize, TY_CHAR)
nchars = bfrseq (fp, Memc[bp], pksize)
if (nchars != EOF) {
nelem = min (maxelem, miinelem (nchars, MII_LONG))
call miiupkl (Memc[bp], spp, nelem, TY_LONG)
}
call sfree (sp)
} else {
# Read data into user buffer and unpack in place.
nchars = bfrseq (fp, spp, pksize)
if (nchars != EOF) {
nelem = min (maxelem, miinelem (nchars, MII_LONG))
call miiupkl (spp, spp, nelem, TY_LONG)
}
}
return (nelem)
end
# MIIRDR -- Read a block of data stored externally in MII real format.
# Data is returned in the format of the local host machine.
int procedure i_miirdr (fp, spp, maxelem)
pointer fp #I input file
real spp[ARB] #O receives data
int maxelem # max number of data elements to be read
pointer sp, bp
int pksize, nchars, nelem
int miipksize(), miinelem(), bfrseq()
begin
pksize = miipksize (maxelem, MII_REAL)
nelem = EOF
if (pksize > maxelem * SZ_REAL) {
# Read data into local buffer and unpack into user buffer.
call smark (sp)
call salloc (bp, pksize, TY_CHAR)
nchars = bfrseq (fp, Memc[bp], pksize)
if (nchars != EOF) {
nelem = min (maxelem, miinelem (nchars, MII_REAL))
call miiupkr (Memc[bp], spp, nelem, TY_REAL)
}
call sfree (sp)
} else {
# Read data into user buffer and unpack in place.
nchars = bfrseq (fp, spp, pksize)
if (nchars != EOF) {
nelem = min (maxelem, miinelem (nchars, MII_REAL))
call miiupkr (spp, spp, nelem, TY_REAL)
}
}
return (nelem)
end
# MIIWRI -- Write a block of data to a file in MII integer format.
# The input data is in the host system native binary format.
int procedure i_miiwri (fp, spp, nelem)
pointer fp #I output file
int spp[ARB] #I native format data to be written
int nelem #I number of data elements to be written
pointer sp, bp
int bufsize, status
int miipksize(), bfwseq()
begin
status = OK
call smark (sp)
bufsize = miipksize (nelem, MII_INT)
call salloc (bp, bufsize, TY_CHAR)
call miipaki (spp, Memc[bp], nelem, TY_INT)
if (bfwseq (fp, Memc[bp], bufsize) == ERR)
status = ERR
call sfree (sp)
return (status)
end
# MIIWRL -- Write a block of data to a file in MII long integer format.
# The input data is in the host system native binary format.
int procedure i_miiwrl (fp, spp, nelem)
pointer fp #I output file
long spp[ARB] #I native format data to be written
int nelem #I number of data elements to be written
pointer sp, bp
int bufsize, status
int miipksize(), bfwseq()
begin
status = OK
call smark (sp)
bufsize = miipksize (nelem, MII_LONG)
call salloc (bp, bufsize, TY_CHAR)
call miipakl (spp, Memc[bp], nelem, TY_LONG)
if (bfwseq (fp, Memc[bp], bufsize) == ERR)
status = ERR
call sfree (sp)
return (status)
end
# MIIWRR -- Write a block of data to a file in MII real format.
# The input data is in the host system native binary format.
int procedure i_miiwrr (fp, spp, nelem)
pointer fp #I output file
real spp[ARB] #I native format data to be written
int nelem #I number of data elements to be written
pointer sp, bp
int bufsize, status
int miipksize(), bfwseq()
begin
status = OK
call smark (sp)
bufsize = miipksize (nelem, MII_REAL)
call salloc (bp, bufsize, TY_CHAR)
call miipakr (spp, Memc[bp], nelem, TY_REAL)
if (bfwseq (fp, Memc[bp], bufsize) == ERR)
status = ERR
call sfree (sp)
return (status)
end
# MIIRDC -- Read a block of character data stored externally in MII format.
# Data is returned in the machine independent character format.
int procedure i_miirdc (fp, spp, maxchars)
pointer fp #I input file
char spp[ARB] #O receives data
int maxchars #I max number of chars to be read
pointer sp, bp
int pksize, nchars
int miipksize(), miinelem(), bfrseq()
begin
pksize = miipksize (maxchars, MII_BYTE)
nchars = max (maxchars, pksize)
if (nchars > maxchars) {
# Read data into local buffer and unpack into user buffer.
call smark (sp)
call salloc (bp, nchars, TY_CHAR)
nchars = bfrseq (fp, Memc[bp], pksize)
if (nchars != EOF) {
nchars = min (maxchars, miinelem (nchars, MII_BYTE))
call miiupk8 (Memc[bp], spp, nchars, TY_CHAR)
}
call sfree (sp)
} else {
# Read data into user buffer and unpack in place.
nchars = bfrseq (fp, spp, pksize)
if (nchars != EOF) {
nchars = min (maxchars, miinelem (nchars, MII_BYTE))
call miiupk8 (spp, spp, nchars, TY_CHAR)
}
}
return (nchars)
end
# MIIWRC -- Write a block of character data to a file in MII format.
# The input data is assumed to be in a machine independent format.
int procedure i_miiwrc (fp, spp, nchars)
pointer fp #I output file
char spp[ARB] #I data to be written
int nchars #I number of chars units to be written
pointer sp, bp
int bufsize, status
int miipksize(), bfwseq()
begin
status = OK
call smark (sp)
bufsize = miipksize (nchars, MII_BYTE)
call salloc (bp, bufsize, TY_CHAR)
call miipak8 (spp, Memc[bp], nchars, TY_CHAR)
if (bfwseq (fp, Memc[bp], bufsize) == ERR)
status = ERR
call sfree (sp)
return (status)
end
|