@loaders.gl/netcdf 3.1.3 → 4.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -7
- package/dist/index.js.map +1 -0
- package/dist/iobuffer/iobuffer.js +370 -425
- package/dist/iobuffer/iobuffer.js.map +1 -0
- package/dist/netcdf-loader.js +36 -46
- package/dist/netcdf-loader.js.map +1 -0
- package/dist/{es5/netcdfjs → netcdfjs}/LICENSE +0 -0
- package/dist/netcdfjs/netcdf-reader.js +126 -155
- package/dist/netcdfjs/netcdf-reader.js.map +1 -0
- package/dist/netcdfjs/netcdf-types.js +2 -2
- package/dist/{es5/netcdfjs → netcdfjs}/netcdf-types.js.map +0 -0
- package/dist/netcdfjs/read-data.js +26 -47
- package/dist/netcdfjs/read-data.js.map +1 -0
- package/dist/netcdfjs/read-header.js +173 -206
- package/dist/netcdfjs/read-header.js.map +1 -0
- package/dist/netcdfjs/read-type.js +117 -130
- package/dist/netcdfjs/read-type.js.map +1 -0
- package/package.json +5 -5
- package/dist/es5/index.js +0 -22
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/iobuffer/iobuffer.js +0 -432
- package/dist/es5/iobuffer/iobuffer.js.map +0 -1
- package/dist/es5/netcdf-loader.js +0 -105
- package/dist/es5/netcdf-loader.js.map +0 -1
- package/dist/es5/netcdfjs/netcdf-reader.js +0 -207
- package/dist/es5/netcdfjs/netcdf-reader.js.map +0 -1
- package/dist/es5/netcdfjs/netcdf-types.js +0 -2
- package/dist/es5/netcdfjs/read-data.js +0 -38
- package/dist/es5/netcdfjs/read-data.js.map +0 -1
- package/dist/es5/netcdfjs/read-header.js +0 -207
- package/dist/es5/netcdfjs/read-header.js.map +0 -1
- package/dist/es5/netcdfjs/read-type.js +0 -142
- package/dist/es5/netcdfjs/read-type.js.map +0 -1
- package/dist/esm/index.js +0 -3
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/iobuffer/iobuffer.js +0 -372
- package/dist/esm/iobuffer/iobuffer.js.map +0 -1
- package/dist/esm/netcdf-loader.js +0 -42
- package/dist/esm/netcdf-loader.js.map +0 -1
- package/dist/esm/netcdfjs/LICENSE +0 -24
- package/dist/esm/netcdfjs/netcdf-reader.js +0 -136
- package/dist/esm/netcdfjs/netcdf-reader.js.map +0 -1
- package/dist/esm/netcdfjs/netcdf-types.js +0 -2
- package/dist/esm/netcdfjs/netcdf-types.js.map +0 -1
- package/dist/esm/netcdfjs/read-data.js +0 -28
- package/dist/esm/netcdfjs/read-data.js.map +0 -1
- package/dist/esm/netcdfjs/read-header.js +0 -197
- package/dist/esm/netcdfjs/read-header.js.map +0 -1
- package/dist/esm/netcdfjs/read-type.js +0 -127
- package/dist/esm/netcdfjs/read-type.js.map +0 -1
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":["NetCDFReader","NetCDFLoader"],"mappings":"AAAA,SAAQA,YAAR,QAA2B,0BAA3B;AAEA,SAAQC,YAAR,QAA2B,iBAA3B","sourcesContent":["export {NetCDFReader} from './netcdfjs/netcdf-reader';\n\nexport {NetCDFLoader} from './netcdf-loader';\n"],"file":"index.js"}
|
|
@@ -1,372 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
const DEFAULT_BYTE_LENGTH = 1024 * 8;
|
|
3
|
-
export class IOBuffer {
|
|
4
|
-
constructor(data = DEFAULT_BYTE_LENGTH, options = {}) {
|
|
5
|
-
_defineProperty(this, "buffer", void 0);
|
|
6
|
-
|
|
7
|
-
_defineProperty(this, "byteLength", void 0);
|
|
8
|
-
|
|
9
|
-
_defineProperty(this, "byteOffset", void 0);
|
|
10
|
-
|
|
11
|
-
_defineProperty(this, "length", void 0);
|
|
12
|
-
|
|
13
|
-
_defineProperty(this, "offset", void 0);
|
|
14
|
-
|
|
15
|
-
_defineProperty(this, "lastWrittenByte", void 0);
|
|
16
|
-
|
|
17
|
-
_defineProperty(this, "littleEndian", void 0);
|
|
18
|
-
|
|
19
|
-
_defineProperty(this, "_data", void 0);
|
|
20
|
-
|
|
21
|
-
_defineProperty(this, "_mark", void 0);
|
|
22
|
-
|
|
23
|
-
_defineProperty(this, "_marks", void 0);
|
|
24
|
-
|
|
25
|
-
_defineProperty(this, "textDecoder", new TextDecoder());
|
|
26
|
-
|
|
27
|
-
_defineProperty(this, "textEncoder", new TextEncoder());
|
|
28
|
-
|
|
29
|
-
let dataIsGiven = false;
|
|
30
|
-
|
|
31
|
-
if (typeof data === 'number') {
|
|
32
|
-
data = new ArrayBuffer(data);
|
|
33
|
-
} else {
|
|
34
|
-
dataIsGiven = true;
|
|
35
|
-
this.lastWrittenByte = data.byteLength;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const offset = options.offset ? options.offset >>> 0 : 0;
|
|
39
|
-
const byteLength = data.byteLength - offset;
|
|
40
|
-
let dvOffset = offset;
|
|
41
|
-
|
|
42
|
-
if (ArrayBuffer.isView(data) || data instanceof IOBuffer) {
|
|
43
|
-
if (data.byteLength !== data.buffer.byteLength) {
|
|
44
|
-
dvOffset = data.byteOffset + offset;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
data = data.buffer;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (dataIsGiven) {
|
|
51
|
-
this.lastWrittenByte = byteLength;
|
|
52
|
-
} else {
|
|
53
|
-
this.lastWrittenByte = 0;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
this.buffer = data;
|
|
57
|
-
this.length = byteLength;
|
|
58
|
-
this.byteLength = byteLength;
|
|
59
|
-
this.byteOffset = dvOffset;
|
|
60
|
-
this.offset = 0;
|
|
61
|
-
this.littleEndian = true;
|
|
62
|
-
this._data = new DataView(this.buffer, dvOffset, byteLength);
|
|
63
|
-
this._mark = 0;
|
|
64
|
-
this._marks = [];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
available(byteLength = 1) {
|
|
68
|
-
return this.offset + byteLength <= this.length;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
isLittleEndian() {
|
|
72
|
-
return this.littleEndian;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
setLittleEndian() {
|
|
76
|
-
this.littleEndian = true;
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
isBigEndian() {
|
|
81
|
-
return !this.littleEndian;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
setBigEndian() {
|
|
85
|
-
this.littleEndian = false;
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
skip(n = 1) {
|
|
90
|
-
this.offset += n;
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
seek(offset) {
|
|
95
|
-
this.offset = offset;
|
|
96
|
-
return this;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
mark() {
|
|
100
|
-
this._mark = this.offset;
|
|
101
|
-
return this;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
reset() {
|
|
105
|
-
this.offset = this._mark;
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
pushMark() {
|
|
110
|
-
this._marks.push(this.offset);
|
|
111
|
-
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
popMark() {
|
|
116
|
-
const offset = this._marks.pop();
|
|
117
|
-
|
|
118
|
-
if (offset === undefined) {
|
|
119
|
-
throw new Error('Mark stack empty');
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
this.seek(offset);
|
|
123
|
-
return this;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
rewind() {
|
|
127
|
-
this.offset = 0;
|
|
128
|
-
return this;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
ensureAvailable(byteLength = 1) {
|
|
132
|
-
if (!this.available(byteLength)) {
|
|
133
|
-
const lengthNeeded = this.offset + byteLength;
|
|
134
|
-
const newLength = lengthNeeded * 2;
|
|
135
|
-
const newArray = new Uint8Array(newLength);
|
|
136
|
-
newArray.set(new Uint8Array(this.buffer));
|
|
137
|
-
this.buffer = newArray.buffer;
|
|
138
|
-
this.length = this.byteLength = newLength;
|
|
139
|
-
this._data = new DataView(this.buffer);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
readBoolean() {
|
|
146
|
-
return this.readUint8() !== 0;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
readInt8() {
|
|
150
|
-
return this._data.getInt8(this.offset++);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
readUint8() {
|
|
154
|
-
return this._data.getUint8(this.offset++);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
readByte() {
|
|
158
|
-
return this.readUint8();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
readBytes(n = 1) {
|
|
162
|
-
const bytes = new Uint8Array(n);
|
|
163
|
-
|
|
164
|
-
for (let i = 0; i < n; i++) {
|
|
165
|
-
bytes[i] = this.readByte();
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return bytes;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
readInt16() {
|
|
172
|
-
const value = this._data.getInt16(this.offset, this.littleEndian);
|
|
173
|
-
|
|
174
|
-
this.offset += 2;
|
|
175
|
-
return value;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
readUint16() {
|
|
179
|
-
const value = this._data.getUint16(this.offset, this.littleEndian);
|
|
180
|
-
|
|
181
|
-
this.offset += 2;
|
|
182
|
-
return value;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
readInt32() {
|
|
186
|
-
const value = this._data.getInt32(this.offset, this.littleEndian);
|
|
187
|
-
|
|
188
|
-
this.offset += 4;
|
|
189
|
-
return value;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
readUint32() {
|
|
193
|
-
const value = this._data.getUint32(this.offset, this.littleEndian);
|
|
194
|
-
|
|
195
|
-
this.offset += 4;
|
|
196
|
-
return value;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
readFloat32() {
|
|
200
|
-
const value = this._data.getFloat32(this.offset, this.littleEndian);
|
|
201
|
-
|
|
202
|
-
this.offset += 4;
|
|
203
|
-
return value;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
readFloat64() {
|
|
207
|
-
const value = this._data.getFloat64(this.offset, this.littleEndian);
|
|
208
|
-
|
|
209
|
-
this.offset += 8;
|
|
210
|
-
return value;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
readChar() {
|
|
214
|
-
return String.fromCharCode(this.readInt8());
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
readChars(n = 1) {
|
|
218
|
-
let result = '';
|
|
219
|
-
|
|
220
|
-
for (let i = 0; i < n; i++) {
|
|
221
|
-
result += this.readChar();
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return result;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
readUtf8(n = 1) {
|
|
228
|
-
return this.textDecoder.decode(this.readBytes(n));
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
writeBoolean(value) {
|
|
232
|
-
this.writeUint8(value ? 0xff : 0x00);
|
|
233
|
-
return this;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
writeInt8(value) {
|
|
237
|
-
this.ensureAvailable(1);
|
|
238
|
-
|
|
239
|
-
this._data.setInt8(this.offset++, value);
|
|
240
|
-
|
|
241
|
-
this._updateLastWrittenByte();
|
|
242
|
-
|
|
243
|
-
return this;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
writeUint8(value) {
|
|
247
|
-
this.ensureAvailable(1);
|
|
248
|
-
|
|
249
|
-
this._data.setUint8(this.offset++, value);
|
|
250
|
-
|
|
251
|
-
this._updateLastWrittenByte();
|
|
252
|
-
|
|
253
|
-
return this;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
writeByte(value) {
|
|
257
|
-
return this.writeUint8(value);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
writeBytes(bytes) {
|
|
261
|
-
this.ensureAvailable(bytes.length);
|
|
262
|
-
|
|
263
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
264
|
-
this._data.setUint8(this.offset++, bytes[i]);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
this._updateLastWrittenByte();
|
|
268
|
-
|
|
269
|
-
return this;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
writeInt16(value) {
|
|
273
|
-
this.ensureAvailable(2);
|
|
274
|
-
|
|
275
|
-
this._data.setInt16(this.offset, value, this.littleEndian);
|
|
276
|
-
|
|
277
|
-
this.offset += 2;
|
|
278
|
-
|
|
279
|
-
this._updateLastWrittenByte();
|
|
280
|
-
|
|
281
|
-
return this;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
writeUint16(value) {
|
|
285
|
-
this.ensureAvailable(2);
|
|
286
|
-
|
|
287
|
-
this._data.setUint16(this.offset, value, this.littleEndian);
|
|
288
|
-
|
|
289
|
-
this.offset += 2;
|
|
290
|
-
|
|
291
|
-
this._updateLastWrittenByte();
|
|
292
|
-
|
|
293
|
-
return this;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
writeInt32(value) {
|
|
297
|
-
this.ensureAvailable(4);
|
|
298
|
-
|
|
299
|
-
this._data.setInt32(this.offset, value, this.littleEndian);
|
|
300
|
-
|
|
301
|
-
this.offset += 4;
|
|
302
|
-
|
|
303
|
-
this._updateLastWrittenByte();
|
|
304
|
-
|
|
305
|
-
return this;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
writeUint32(value) {
|
|
309
|
-
this.ensureAvailable(4);
|
|
310
|
-
|
|
311
|
-
this._data.setUint32(this.offset, value, this.littleEndian);
|
|
312
|
-
|
|
313
|
-
this.offset += 4;
|
|
314
|
-
|
|
315
|
-
this._updateLastWrittenByte();
|
|
316
|
-
|
|
317
|
-
return this;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
writeFloat32(value) {
|
|
321
|
-
this.ensureAvailable(4);
|
|
322
|
-
|
|
323
|
-
this._data.setFloat32(this.offset, value, this.littleEndian);
|
|
324
|
-
|
|
325
|
-
this.offset += 4;
|
|
326
|
-
|
|
327
|
-
this._updateLastWrittenByte();
|
|
328
|
-
|
|
329
|
-
return this;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
writeFloat64(value) {
|
|
333
|
-
this.ensureAvailable(8);
|
|
334
|
-
|
|
335
|
-
this._data.setFloat64(this.offset, value, this.littleEndian);
|
|
336
|
-
|
|
337
|
-
this.offset += 8;
|
|
338
|
-
|
|
339
|
-
this._updateLastWrittenByte();
|
|
340
|
-
|
|
341
|
-
return this;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
writeChar(str) {
|
|
345
|
-
return this.writeUint8(str.charCodeAt(0));
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
writeChars(str) {
|
|
349
|
-
for (let i = 0; i < str.length; i++) {
|
|
350
|
-
this.writeUint8(str.charCodeAt(i));
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
return this;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
writeUtf8(str) {
|
|
357
|
-
const bytes = this.textEncoder.encode(str);
|
|
358
|
-
return this.writeBytes(bytes);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
toArray() {
|
|
362
|
-
return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
_updateLastWrittenByte() {
|
|
366
|
-
if (this.offset > this.lastWrittenByte) {
|
|
367
|
-
this.lastWrittenByte = this.offset;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
}
|
|
372
|
-
//# sourceMappingURL=iobuffer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/iobuffer/iobuffer.ts"],"names":["DEFAULT_BYTE_LENGTH","IOBuffer","constructor","data","options","TextDecoder","TextEncoder","dataIsGiven","ArrayBuffer","lastWrittenByte","byteLength","offset","dvOffset","isView","buffer","byteOffset","length","littleEndian","_data","DataView","_mark","_marks","available","isLittleEndian","setLittleEndian","isBigEndian","setBigEndian","skip","n","seek","mark","reset","pushMark","push","popMark","pop","undefined","Error","rewind","ensureAvailable","lengthNeeded","newLength","newArray","Uint8Array","set","readBoolean","readUint8","readInt8","getInt8","getUint8","readByte","readBytes","bytes","i","readInt16","value","getInt16","readUint16","getUint16","readInt32","getInt32","readUint32","getUint32","readFloat32","getFloat32","readFloat64","getFloat64","readChar","String","fromCharCode","readChars","result","readUtf8","textDecoder","decode","writeBoolean","writeUint8","writeInt8","setInt8","_updateLastWrittenByte","setUint8","writeByte","writeBytes","writeInt16","setInt16","writeUint16","setUint16","writeInt32","setInt32","writeUint32","setUint32","writeFloat32","setFloat32","writeFloat64","setFloat64","writeChar","str","charCodeAt","writeChars","writeUtf8","textEncoder","encode","toArray"],"mappings":";AAAA,MAAMA,mBAAmB,GAAG,OAAO,CAAnC;AAWA,OAAO,MAAMC,QAAN,CAAe;AA4CbC,EAAAA,WAAW,CAACC,IAAe,GAAGH,mBAAnB,EAAwCI,OAAwB,GAAG,EAAnE,EAAuE;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,yCAXnE,IAAIC,WAAJ,EAWmE;;AAAA,yCAVnE,IAAIC,WAAJ,EAUmE;;AACvF,QAAIC,WAAW,GAAG,KAAlB;;AACA,QAAI,OAAOJ,IAAP,KAAgB,QAApB,EAA8B;AAC5BA,MAAAA,IAAI,GAAG,IAAIK,WAAJ,CAAgBL,IAAhB,CAAP;AACD,KAFD,MAEO;AACLI,MAAAA,WAAW,GAAG,IAAd;AACA,WAAKE,eAAL,GAAu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CAAsB,KAAKnF,MAA3B,EAAmC4C,KAAnC,EAA0C,KAAKtC,YAA/C;;AACA,SAAKN,MAAL,IAAe,CAAf;;AACA,SAAKoE,sBAAL;;AACA,WAAO,IAAP;AACD;;AAMMgB,EAAAA,SAAS,CAACC,GAAD,EAAoB;AAClC,WAAO,KAAKpB,UAAL,CAAgBoB,GAAG,CAACC,UAAJ,CAAe,CAAf,CAAhB,CAAP;AACD;;AAMMC,EAAAA,UAAU,CAACF,GAAD,EAAoB;AACnC,SAAK,IAAI3C,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAG2C,GAAG,CAAChF,MAAxB,EAAgCqC,CAAC,EAAjC,EAAqC;AACnC,WAAKuB,UAAL,CAAgBoB,GAAG,CAACC,UAAJ,CAAe5C,CAAf,CAAhB;AACD;;AACD,WAAO,IAAP;AACD;;AAMM8C,EAAAA,SAAS,CAACH,GAAD,EAAoB;AAClC,UAAM5C,KAAK,GAAG,KAAKgD,WAAL,CAAiBC,MAAjB,CAAwBL,GAAxB,CAAd;AACA,WAAO,KAAKd,UAAL,CAAgB9B,KAAhB,CAAP;AACD;;AAOMkD,EAAAA,OAAO,GAAe;AAC3B,WAAO,IAAI3D,UAAJ,CAAe,KAAK7B,MAApB,EAA4B,KAAKC,UAAjC,EAA6C,KAAKN,eAAlD,CAAP;AACD;;AAMOsE,EAAAA,sBAAsB,GAAS;AACrC,QAAI,KAAKpE,MAAL,GAAc,KAAKF,eAAvB,EAAwC;AACtC,WAAKA,eAAL,GAAuB,KAAKE,MAA5B;AACD;AACF;;AA/emB","sourcesContent":["const DEFAULT_BYTE_LENGTH = 1024 * 8;\n\ntype InputData = number | ArrayBufferLike | ArrayBufferView | IOBuffer | Buffer;\n\ninterface IOBufferOptions {\n /**\n * Ignore the first n bytes of the ArrayBuffer.\n */\n offset?: number;\n}\n\nexport class IOBuffer {\n /**\n * Reference to the internal ArrayBuffer object.\n */\n public buffer: ArrayBufferLike;\n\n /**\n * Byte length of the internal ArrayBuffer.\n */\n public byteLength: number;\n\n /**\n * Byte offset of the internal ArrayBuffer.\n */\n public byteOffset: number;\n\n /**\n * Byte length of the internal ArrayBuffer.\n */\n public length: number;\n\n /**\n * The current offset of the buffer's pointer.\n */\n public offset: number;\n\n private lastWrittenByte: number;\n private littleEndian: boolean;\n\n private _data: DataView;\n private _mark: number;\n private _marks: number[];\n\n private textDecoder = new TextDecoder();\n private textEncoder = new TextEncoder();\n\n /**\n * @param data - The data to construct the IOBuffer with.\n * If data is a number, it will be the new buffer's length<br>\n * If data is `undefined`, the buffer will be initialized with a default length of 8Kb<br>\n * If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance,\n * or a Node.js Buffer, a view will be created over the underlying ArrayBuffer.\n * @param options\n */\n public constructor(data: InputData = DEFAULT_BYTE_LENGTH, options: IOBufferOptions = {}) {\n let dataIsGiven = false;\n if (typeof data === 'number') {\n data = new ArrayBuffer(data);\n } else {\n dataIsGiven = true;\n this.lastWrittenByte = data.byteLength;\n }\n\n const offset = options.offset ? options.offset >>> 0 : 0;\n const byteLength = data.byteLength - offset;\n let dvOffset = offset;\n if (ArrayBuffer.isView(data) || data instanceof IOBuffer) {\n if (data.byteLength !== data.buffer.byteLength) {\n dvOffset = data.byteOffset + offset;\n }\n data = data.buffer;\n }\n if (dataIsGiven) {\n this.lastWrittenByte = byteLength;\n } else {\n this.lastWrittenByte = 0;\n }\n this.buffer = data;\n this.length = byteLength;\n this.byteLength = byteLength;\n this.byteOffset = dvOffset;\n this.offset = 0;\n this.littleEndian = true;\n this._data = new DataView(this.buffer, dvOffset, byteLength);\n this._mark = 0;\n this._marks = [];\n }\n\n /**\n * Checks if the memory allocated to the buffer is sufficient to store more\n * bytes after the offset.\n * @param byteLength - The needed memory in bytes.\n * @returns `true` if there is sufficient space and `false` otherwise.\n */\n public available(byteLength = 1): boolean {\n return this.offset + byteLength <= this.length;\n }\n\n /**\n * Check if little-endian mode is used for reading and writing multi-byte\n * values.\n * @returns `true` if little-endian mode is used, `false` otherwise.\n */\n public isLittleEndian(): boolean {\n return this.littleEndian;\n }\n\n /**\n * Set little-endian mode for reading and writing multi-byte values.\n */\n public setLittleEndian(): this {\n this.littleEndian = true;\n return this;\n }\n\n /**\n * Check if big-endian mode is used for reading and writing multi-byte values.\n * @returns `true` if big-endian mode is used, `false` otherwise.\n */\n public isBigEndian(): boolean {\n return !this.littleEndian;\n }\n\n /**\n * Switches to big-endian mode for reading and writing multi-byte values.\n */\n public setBigEndian(): this {\n this.littleEndian = false;\n return this;\n }\n\n /**\n * Move the pointer n bytes forward.\n * @param n - Number of bytes to skip.\n */\n public skip(n = 1): this {\n this.offset += n;\n return this;\n }\n\n /**\n * Move the pointer to the given offset.\n * @param offset\n */\n public seek(offset: number): this {\n this.offset = offset;\n return this;\n }\n\n /**\n * Store the current pointer offset.\n * @see {@link IOBuffer#reset}\n */\n public mark(): this {\n this._mark = this.offset;\n return this;\n }\n\n /**\n * Move the pointer back to the last pointer offset set by mark.\n * @see {@link IOBuffer#mark}\n */\n public reset(): this {\n this.offset = this._mark;\n return this;\n }\n\n /**\n * Push the current pointer offset to the mark stack.\n * @see {@link IOBuffer#popMark}\n */\n public pushMark(): this {\n this._marks.push(this.offset);\n return this;\n }\n\n /**\n * Pop the last pointer offset from the mark stack, and set the current\n * pointer offset to the popped value.\n * @see {@link IOBuffer#pushMark}\n */\n public popMark(): this {\n const offset = this._marks.pop();\n if (offset === undefined) {\n throw new Error('Mark stack empty');\n }\n this.seek(offset);\n return this;\n }\n\n /**\n * Move the pointer offset back to 0.\n */\n public rewind(): this {\n this.offset = 0;\n return this;\n }\n\n /**\n * Make sure the buffer has sufficient memory to write a given byteLength at\n * the current pointer offset.\n * If the buffer's memory is insufficient, this method will create a new\n * buffer (a copy) with a length that is twice (byteLength + current offset).\n * @param byteLength\n */\n public ensureAvailable(byteLength = 1): this {\n if (!this.available(byteLength)) {\n const lengthNeeded = this.offset + byteLength;\n const newLength = lengthNeeded * 2;\n const newArray = new Uint8Array(newLength);\n newArray.set(new Uint8Array(this.buffer));\n this.buffer = newArray.buffer;\n this.length = this.byteLength = newLength;\n this._data = new DataView(this.buffer);\n }\n return this;\n }\n\n /**\n * Read a byte and return false if the byte's value is 0, or true otherwise.\n * Moves pointer forward by one byte.\n */\n public readBoolean(): boolean {\n return this.readUint8() !== 0;\n }\n\n /**\n * Read a signed 8-bit integer and move pointer forward by 1 byte.\n */\n public readInt8(): number {\n return this._data.getInt8(this.offset++);\n }\n\n /**\n * Read an unsigned 8-bit integer and move pointer forward by 1 byte.\n */\n public readUint8(): number {\n return this._data.getUint8(this.offset++);\n }\n\n /**\n * Alias for {@link IOBuffer#readUint8}.\n */\n public readByte(): number {\n return this.readUint8();\n }\n\n /**\n * Read `n` bytes and move pointer forward by `n` bytes.\n */\n public readBytes(n = 1): Uint8Array {\n const bytes = new Uint8Array(n);\n for (let i = 0; i < n; i++) {\n bytes[i] = this.readByte();\n }\n return bytes;\n }\n\n /**\n * Read a 16-bit signed integer and move pointer forward by 2 bytes.\n */\n public readInt16(): number {\n const value = this._data.getInt16(this.offset, this.littleEndian);\n this.offset += 2;\n return value;\n }\n\n /**\n * Read a 16-bit unsigned integer and move pointer forward by 2 bytes.\n */\n public readUint16(): number {\n const value = this._data.getUint16(this.offset, this.littleEndian);\n this.offset += 2;\n return value;\n }\n\n /**\n * Read a 32-bit signed integer and move pointer forward by 4 bytes.\n */\n public readInt32(): number {\n const value = this._data.getInt32(this.offset, this.littleEndian);\n this.offset += 4;\n return value;\n }\n\n /**\n * Read a 32-bit unsigned integer and move pointer forward by 4 bytes.\n */\n public readUint32(): number {\n const value = this._data.getUint32(this.offset, this.littleEndian);\n this.offset += 4;\n return value;\n }\n\n /**\n * Read a 32-bit floating number and move pointer forward by 4 bytes.\n */\n public readFloat32(): number {\n const value = this._data.getFloat32(this.offset, this.littleEndian);\n this.offset += 4;\n return value;\n }\n\n /**\n * Read a 64-bit floating number and move pointer forward by 8 bytes.\n */\n public readFloat64(): number {\n const value = this._data.getFloat64(this.offset, this.littleEndian);\n this.offset += 8;\n return value;\n }\n\n /**\n * Read a 1-byte ASCII character and move pointer forward by 1 byte.\n */\n public readChar(): string {\n return String.fromCharCode(this.readInt8());\n }\n\n /**\n * Read `n` 1-byte ASCII characters and move pointer forward by `n` bytes.\n */\n public readChars(n = 1): string {\n let result = '';\n for (let i = 0; i < n; i++) {\n result += this.readChar();\n }\n return result;\n }\n\n /**\n * Read the next `n` bytes, return a UTF-8 decoded string and move pointer\n * forward by `n` bytes.\n */\n public readUtf8(n = 1): string {\n return this.textDecoder.decode(this.readBytes(n));\n }\n\n /**\n * Write 0xff if the passed value is truthy, 0x00 otherwise and move pointer\n * forward by 1 byte.\n */\n public writeBoolean(value: unknown): this {\n this.writeUint8(value ? 0xff : 0x00);\n return this;\n }\n\n /**\n * Write `value` as an 8-bit signed integer and move pointer forward by 1 byte.\n */\n public writeInt8(value: number): this {\n this.ensureAvailable(1);\n this._data.setInt8(this.offset++, value);\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as an 8-bit unsigned integer and move pointer forward by 1\n * byte.\n */\n public writeUint8(value: number): this {\n this.ensureAvailable(1);\n this._data.setUint8(this.offset++, value);\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * An alias for {@link IOBuffer#writeUint8}.\n */\n public writeByte(value: number): this {\n return this.writeUint8(value);\n }\n\n /**\n * Write all elements of `bytes` as uint8 values and move pointer forward by\n * `bytes.length` bytes.\n */\n public writeBytes(bytes: ArrayLike<number>): this {\n this.ensureAvailable(bytes.length);\n for (let i = 0; i < bytes.length; i++) {\n this._data.setUint8(this.offset++, bytes[i]);\n }\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 16-bit signed integer and move pointer forward by 2\n * bytes.\n */\n public writeInt16(value: number): this {\n this.ensureAvailable(2);\n this._data.setInt16(this.offset, value, this.littleEndian);\n this.offset += 2;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 16-bit unsigned integer and move pointer forward by 2\n * bytes.\n */\n public writeUint16(value: number): this {\n this.ensureAvailable(2);\n this._data.setUint16(this.offset, value, this.littleEndian);\n this.offset += 2;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 32-bit signed integer and move pointer forward by 4\n * bytes.\n */\n public writeInt32(value: number): this {\n this.ensureAvailable(4);\n this._data.setInt32(this.offset, value, this.littleEndian);\n this.offset += 4;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 32-bit unsigned integer and move pointer forward by 4\n * bytes.\n */\n public writeUint32(value: number): this {\n this.ensureAvailable(4);\n this._data.setUint32(this.offset, value, this.littleEndian);\n this.offset += 4;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 32-bit floating number and move pointer forward by 4\n * bytes.\n */\n public writeFloat32(value: number): this {\n this.ensureAvailable(4);\n this._data.setFloat32(this.offset, value, this.littleEndian);\n this.offset += 4;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write `value` as a 64-bit floating number and move pointer forward by 8\n * bytes.\n */\n public writeFloat64(value: number): this {\n this.ensureAvailable(8);\n this._data.setFloat64(this.offset, value, this.littleEndian);\n this.offset += 8;\n this._updateLastWrittenByte();\n return this;\n }\n\n /**\n * Write the charCode of `str`'s first character as an 8-bit unsigned integer\n * and move pointer forward by 1 byte.\n */\n public writeChar(str: string): this {\n return this.writeUint8(str.charCodeAt(0));\n }\n\n /**\n * Write the charCodes of all `str`'s characters as 8-bit unsigned integers\n * and move pointer forward by `str.length` bytes.\n */\n public writeChars(str: string): this {\n for (let i = 0; i < str.length; i++) {\n this.writeUint8(str.charCodeAt(i));\n }\n return this;\n }\n\n /**\n * UTF-8 encode and write `str` to the current pointer offset and move pointer\n * forward according to the encoded length.\n */\n public writeUtf8(str: string): this {\n const bytes = this.textEncoder.encode(str);\n return this.writeBytes(bytes);\n }\n\n /**\n * Export a Uint8Array view of the internal buffer.\n * The view starts at the byte offset and its length\n * is calculated to stop at the last written byte or the original length.\n */\n public toArray(): Uint8Array {\n return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte);\n }\n\n /**\n * Update the last written byte offset\n * @private\n */\n private _updateLastWrittenByte(): void {\n if (this.offset > this.lastWrittenByte) {\n this.lastWrittenByte = this.offset;\n }\n }\n}\n"],"file":"iobuffer.js"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { NetCDFReader } from './netcdfjs/netcdf-reader';
|
|
2
|
-
const VERSION = typeof "3.1.3" !== 'undefined' ? "3.1.3" : 'latest';
|
|
3
|
-
export const NetCDFWorkerLoader = {
|
|
4
|
-
name: 'NetCDF',
|
|
5
|
-
id: 'mvt',
|
|
6
|
-
module: 'mvt',
|
|
7
|
-
version: VERSION,
|
|
8
|
-
extensions: ['cdf', 'nc'],
|
|
9
|
-
mimeTypes: ['application/netcdf', 'application/x-netcdf'],
|
|
10
|
-
category: 'image',
|
|
11
|
-
options: {
|
|
12
|
-
netcdf: {
|
|
13
|
-
loadVariables: false
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
export const NetCDFLoader = { ...NetCDFWorkerLoader,
|
|
18
|
-
parse: async (arrayBuffer, options) => parseNetCDF(arrayBuffer, options),
|
|
19
|
-
binary: true
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
function parseNetCDF(arrayBuffer, options) {
|
|
23
|
-
var _options$netcdf;
|
|
24
|
-
|
|
25
|
-
const reader = new NetCDFReader(arrayBuffer);
|
|
26
|
-
const variables = {};
|
|
27
|
-
|
|
28
|
-
if (options !== null && options !== void 0 && (_options$netcdf = options.netcdf) !== null && _options$netcdf !== void 0 && _options$netcdf.loadData) {
|
|
29
|
-
for (const variable of reader.variables) {
|
|
30
|
-
variables[variable.name] = reader.getDataVariable(variable);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
loaderData: reader.header,
|
|
36
|
-
data: variables
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const _typecheckNetCDFWorkerLoader = NetCDFWorkerLoader;
|
|
41
|
-
export const _typecheckNetCDFLoader = NetCDFLoader;
|
|
42
|
-
//# sourceMappingURL=netcdf-loader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/netcdf-loader.ts"],"names":["NetCDFReader","VERSION","NetCDFWorkerLoader","name","id","module","version","extensions","mimeTypes","category","options","netcdf","loadVariables","NetCDFLoader","parse","arrayBuffer","parseNetCDF","binary","reader","variables","loadData","variable","getDataVariable","loaderData","header","data","_typecheckNetCDFWorkerLoader","_typecheckNetCDFLoader"],"mappings":"AAEA,SAAQA,YAAR,QAA2B,0BAA3B;AAIA,MAAMC,OAAO,GAAG,mBAAuB,WAAvB,aAAmD,QAAnE;AAgBA,OAAO,MAAMC,kBAAkB,GAAG;AAChCC,EAAAA,IAAI,EAAE,QAD0B;AAEhCC,EAAAA,EAAE,EAAE,KAF4B;AAGhCC,EAAAA,MAAM,EAAE,KAHwB;AAIhCC,EAAAA,OAAO,EAAEL,OAJuB;AAKhCM,EAAAA,UAAU,EAAE,CAAC,KAAD,EAAQ,IAAR,CALoB;AAMhCC,EAAAA,SAAS,EAAE,CACT,oBADS,EAET,sBAFS,CANqB;AAWhCC,EAAAA,QAAQ,EAAE,OAXsB;AAYhCC,EAAAA,OAAO,EAAE;AACPC,IAAAA,MAAM,EAAE;AACNC,MAAAA,aAAa,EAAE;AADT;AADD;AAZuB,CAA3B;AAsBP,OAAO,MAAMC,YAAY,GAAG,EAC1B,GAAGX,kBADuB;AAE1BY,EAAAA,KAAK,EAAE,OAAOC,WAAP,EAAoBL,OAApB,KAAgCM,WAAW,CAACD,WAAD,EAAcL,OAAd,CAFxB;AAG1BO,EAAAA,MAAM,EAAE;AAHkB,CAArB;;AAMP,SAASD,WAAT,CAAqBD,WAArB,EAA+CL,OAA/C,EAAsF;AAAA;;AACpF,QAAMQ,MAAM,GAAG,IAAIlB,YAAJ,CAAiBe,WAAjB,CAAf;AACA,QAAMI,SAA4C,GAAG,EAArD;;AACA,MAAIT,OAAJ,aAAIA,OAAJ,kCAAIA,OAAO,CAAEC,MAAb,4CAAI,gBAAiBS,QAArB,EAA+B;AAC7B,SAAK,MAAMC,QAAX,IAAuBH,MAAM,CAACC,SAA9B,EAAyC;AACvCA,MAAAA,SAAS,CAACE,QAAQ,CAAClB,IAAV,CAAT,GAA2Be,MAAM,CAACI,eAAP,CAAuBD,QAAvB,CAA3B;AACD;AACF;;AACD,SAAO;AACLE,IAAAA,UAAU,EAAEL,MAAM,CAACM,MADd;AAELC,IAAAA,IAAI,EAAEN;AAFD,GAAP;AAID;;AAGD,OAAO,MAAMO,4BAAoC,GAAGxB,kBAA7C;AACP,OAAO,MAAMyB,sBAAwC,GAAGd,YAAjD","sourcesContent":["import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {NetCDFHeader} from './netcdfjs/netcdf-types';\nimport {NetCDFReader} from './netcdfjs/netcdf-reader';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type NetCDF = {\n loaderData: NetCDFHeader;\n data: {[variableName: string]: any[][]};\n};\n\nexport type NetCDFLoaderOptions = LoaderOptions & {\n netcdf?: {\n loadData?: boolean;\n };\n};\n\n/**\n * Worker loader for NETCDF\n */\nexport const NetCDFWorkerLoader = {\n name: 'NetCDF',\n id: 'mvt',\n module: 'mvt',\n version: VERSION,\n extensions: ['cdf', 'nc'],\n mimeTypes: [\n 'application/netcdf',\n 'application/x-netcdf'\n // 'application/octet-stream'\n ],\n category: 'image',\n options: {\n netcdf: {\n loadVariables: false\n }\n }\n};\n\n/**\n * Loader for the NetCDF format\n */\nexport const NetCDFLoader = {\n ...NetCDFWorkerLoader,\n parse: async (arrayBuffer, options) => parseNetCDF(arrayBuffer, options),\n binary: true\n};\n\nfunction parseNetCDF(arrayBuffer: ArrayBuffer, options?: NetCDFLoaderOptions): NetCDF {\n const reader = new NetCDFReader(arrayBuffer);\n const variables: {[variableName: string]: any[][]} = {};\n if (options?.netcdf?.loadData) {\n for (const variable of reader.variables) {\n variables[variable.name] = reader.getDataVariable(variable);\n }\n }\n return {\n loaderData: reader.header,\n data: variables\n };\n}\n\n// Type tests\nexport const _typecheckNetCDFWorkerLoader: Loader = NetCDFWorkerLoader;\nexport const _typecheckNetCDFLoader: LoaderWithParser = NetCDFLoader;\n"],"file":"netcdf-loader.js"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
This directory is forked from https://github.com/cheminfo/netcdfjs
|
|
2
|
-
|
|
3
|
-
The MIT License (MIT)
|
|
4
|
-
|
|
5
|
-
Copyright (c) 2016 cheminfo
|
|
6
|
-
|
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
in the Software without restriction, including without limitation the rights
|
|
10
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
furnished to do so, subject to the following conditions:
|
|
13
|
-
|
|
14
|
-
The above copyright notice and this permission notice shall be included in all
|
|
15
|
-
copies or substantial portions of the Software.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
-
SOFTWARE.
|
|
24
|
-
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
import { IOBuffer } from '../iobuffer/iobuffer';
|
|
3
|
-
import { readNetCDFHeader } from './read-header';
|
|
4
|
-
import { readRecord, readNonRecord } from './read-data';
|
|
5
|
-
export class NetCDFReader {
|
|
6
|
-
constructor(data) {
|
|
7
|
-
_defineProperty(this, "header", void 0);
|
|
8
|
-
|
|
9
|
-
_defineProperty(this, "buffer", void 0);
|
|
10
|
-
|
|
11
|
-
const buffer = new IOBuffer(data);
|
|
12
|
-
buffer.setBigEndian();
|
|
13
|
-
const magic = buffer.readChars(3);
|
|
14
|
-
|
|
15
|
-
if (magic !== 'CDF') {
|
|
16
|
-
throw new Error("NetCDF: file should start with 'CDF', found ".concat(magic));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const version = buffer.readByte();
|
|
20
|
-
|
|
21
|
-
if (version > 2) {
|
|
22
|
-
throw new Error("NetCDF: unsupported version ".concat(version));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
this.header = readNetCDFHeader(buffer, version);
|
|
26
|
-
this.buffer = buffer;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
get version() {
|
|
30
|
-
if (this.header.version === 1) {
|
|
31
|
-
return 'classic format';
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return '64-bit offset format';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get recordDimension() {
|
|
38
|
-
return this.header.recordDimension;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get dimensions() {
|
|
42
|
-
return this.header.dimensions;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get attributes() {
|
|
46
|
-
return this.header.attributes;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get variables() {
|
|
50
|
-
return this.header.variables;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
attributeExists(attributeName) {
|
|
54
|
-
const attribute = this.attributes.find(val => val.name === attributeName);
|
|
55
|
-
return attribute !== undefined;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
getAttribute(attributeName) {
|
|
59
|
-
const attribute = this.attributes.find(val => val.name === attributeName);
|
|
60
|
-
if (attribute) return attribute.value;
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
dataVariableExists(variableName) {
|
|
65
|
-
const variable = this.header.variables.find(function (val) {
|
|
66
|
-
return val.name === variableName;
|
|
67
|
-
});
|
|
68
|
-
return variable !== undefined;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
getDataVariableAsString(variableName) {
|
|
72
|
-
const variable = this.getDataVariable(variableName);
|
|
73
|
-
if (variable) return variable.join('');
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
getDataVariable(variableName) {
|
|
78
|
-
let variable;
|
|
79
|
-
|
|
80
|
-
if (typeof variableName === 'string') {
|
|
81
|
-
variable = this.header.variables.find(function (val) {
|
|
82
|
-
return val.name === variableName;
|
|
83
|
-
});
|
|
84
|
-
} else {
|
|
85
|
-
variable = variableName;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (variable === undefined) {
|
|
89
|
-
throw new Error("NetCDF: variable not found: ".concat(variableName));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
this.buffer.seek(variable.offset);
|
|
93
|
-
|
|
94
|
-
if (variable.record) {
|
|
95
|
-
return readRecord(this.buffer, variable, this.header.recordDimension);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return readNonRecord(this.buffer, variable);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
toString() {
|
|
102
|
-
const result = [];
|
|
103
|
-
result.push('DIMENSIONS');
|
|
104
|
-
|
|
105
|
-
for (const dimension of this.dimensions) {
|
|
106
|
-
result.push(" ".concat(dimension.name.padEnd(30), " = size: ").concat(dimension.size));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
result.push('');
|
|
110
|
-
result.push('GLOBAL ATTRIBUTES');
|
|
111
|
-
|
|
112
|
-
for (const attribute of this.attributes) {
|
|
113
|
-
result.push(" ".concat(attribute.name.padEnd(30), " = ").concat(attribute.value));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const variables = JSON.parse(JSON.stringify(this.variables));
|
|
117
|
-
result.push('');
|
|
118
|
-
result.push('VARIABLES:');
|
|
119
|
-
|
|
120
|
-
for (const variable of variables) {
|
|
121
|
-
variable.value = this.getDataVariable(variable);
|
|
122
|
-
let stringify = JSON.stringify(variable.value);
|
|
123
|
-
if (stringify.length > 50) stringify = stringify.substring(0, 50);
|
|
124
|
-
|
|
125
|
-
if (!isNaN(variable.value.length)) {
|
|
126
|
-
stringify += " (length: ".concat(variable.value.length, ")");
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
result.push(" ".concat(variable.name.padEnd(30), " = ").concat(stringify));
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return result.join('\n');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
//# sourceMappingURL=netcdf-reader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/netcdfjs/netcdf-reader.ts"],"names":["IOBuffer","readNetCDFHeader","readRecord","readNonRecord","NetCDFReader","constructor","data","buffer","setBigEndian","magic","readChars","Error","version","readByte","header","recordDimension","dimensions","attributes","variables","attributeExists","attributeName","attribute","find","val","name","undefined","getAttribute","value","dataVariableExists","variableName","variable","getDataVariableAsString","getDataVariable","join","seek","offset","record","toString","result","push","dimension","padEnd","size","JSON","parse","stringify","length","substring","isNaN"],"mappings":";AAAA,SAAQA,QAAR,QAAuB,sBAAvB;AAQA,SAAQC,gBAAR,QAA+B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ApB,EAAuB,EAAvB,CAAZ;;AAC3B,UAAI,CAACC,KAAK,CAAClB,QAAQ,CAACH,KAAT,CAAemB,MAAhB,CAAV,EAAmC;AACjCD,QAAAA,SAAS,wBAAiBf,QAAQ,CAACH,KAAT,CAAemB,MAAhC,MAAT;AACD;;AACDR,MAAAA,MAAM,CAACC,IAAP,aAAiBT,QAAQ,CAACN,IAAT,CAAciB,MAAd,CAAqB,EAArB,CAAjB,gBAA+CI,SAA/C;AACD;;AACD,WAAOP,MAAM,CAACL,IAAP,CAAY,IAAZ,CAAP;AACD;;AAzKuB","sourcesContent":["import {IOBuffer} from '../iobuffer/iobuffer';\nimport type {\n NetCDFHeader,\n NetCDFDimension,\n NetCDFRecordDimension,\n NetCDFAttribute,\n NetCDFVariable\n} from './netcdf-types';\nimport {readNetCDFHeader} from './read-header';\nimport {readRecord, readNonRecord} from './read-data';\n\n/**\n * Reads a NetCDF v3.x file\n * https://www.unidata.ucar.edu/software/netcdf/docs/file_format_specifications.html\n * @param {ArrayBuffer} data - ArrayBuffer or any Typed Array (including Node.js' Buffer from v4) with the data\n * @constructor\n */\nexport class NetCDFReader {\n public header: NetCDFHeader;\n public buffer: IOBuffer;\n\n constructor(data) {\n const buffer = new IOBuffer(data);\n buffer.setBigEndian();\n\n // Validate that it's a NetCDF file\n const magic = buffer.readChars(3);\n if (magic !== 'CDF') {\n throw new Error(`NetCDF: file should start with 'CDF', found ${magic}`);\n }\n\n // Check the NetCDF format\n const version = buffer.readByte();\n if (version > 2) {\n throw new Error(`NetCDF: unsupported version ${version}`);\n }\n\n // Read the header\n this.header = readNetCDFHeader(buffer, version);\n this.buffer = buffer;\n }\n\n /**\n * @return {string} - Version for the NetCDF format\n */\n get version() {\n if (this.header.version === 1) {\n return 'classic format';\n }\n return '64-bit offset format';\n }\n\n /**\n * Get metadata for the record dimension\n */\n get recordDimension(): NetCDFRecordDimension {\n return this.header.recordDimension;\n }\n\n /**\n * Get list of dimensions (each with `name` and `size`)\n */\n get dimensions(): NetCDFDimension[] {\n return this.header.dimensions;\n }\n\n /**\n * Get list of global attributes with:\n * * `name`: String with the name of the attribute\n * * `type`: String with the type of the attribute\n * * `value`: A number or string with the value of the attribute\n */\n get attributes(): NetCDFAttribute[] {\n return this.header.attributes;\n }\n\n /**\n * Get list of variables\n */\n get variables(): NetCDFVariable[] {\n return this.header.variables;\n }\n\n /**\n * Check if an attribute exists\n * @param attributeName - Name of the attribute to find\n * @return\n */\n attributeExists(attributeName: string): boolean {\n const attribute = this.attributes.find((val) => val.name === attributeName);\n return attribute !== undefined;\n }\n\n /**\n * Returns the value of an attribute\n * @param attributeName\n * @return Value of the attributeName or null\n */\n getAttribute(attributeName: string): string | null {\n const attribute = this.attributes.find((val) => val.name === attributeName);\n if (attribute) return attribute.value;\n return null;\n }\n\n /**\n * Check if a dataVariable exists\n * @param variableName - Name of the variable to find\n * @return\n */\n dataVariableExists(variableName: string): boolean {\n const variable = this.header.variables.find(function (val) {\n return val.name === variableName;\n });\n return variable !== undefined;\n }\n\n /**\n * Returns the value of a variable as a string\n * @param variableName\n * @return Value of the variable as a string or null\n */\n getDataVariableAsString(variableName: string): string | null {\n const variable = this.getDataVariable(variableName);\n if (variable) return variable.join('');\n return null;\n }\n\n /**\n * Retrieves the data for a given variable\n * @param variableName - Name of the variable to search or variable object\n * @return List with the variable values\n */\n getDataVariable(variableName: string | object): any[] {\n let variable;\n if (typeof variableName === 'string') {\n // search the variable\n variable = this.header.variables.find(function (val) {\n return val.name === variableName;\n });\n } else {\n variable = variableName;\n }\n\n // throws if variable not found\n if (variable === undefined) {\n throw new Error(`NetCDF: variable not found: ${variableName}`);\n }\n\n // go to the offset position\n this.buffer.seek(variable.offset);\n\n if (variable.record) {\n // record variable case\n return readRecord(this.buffer, variable, this.header.recordDimension);\n }\n // non-record variable case\n return readNonRecord(this.buffer, variable);\n }\n\n toString(): string {\n const result: string[] = [];\n\n result.push('DIMENSIONS');\n for (const dimension of this.dimensions) {\n result.push(` ${dimension.name.padEnd(30)} = size: ${dimension.size}`);\n }\n\n result.push('');\n result.push('GLOBAL ATTRIBUTES');\n for (const attribute of this.attributes) {\n result.push(` ${attribute.name.padEnd(30)} = ${attribute.value}`);\n }\n\n const variables = JSON.parse(JSON.stringify(this.variables));\n result.push('');\n result.push('VARIABLES:');\n for (const variable of variables) {\n variable.value = this.getDataVariable(variable);\n let stringify = JSON.stringify(variable.value);\n if (stringify.length > 50) stringify = stringify.substring(0, 50);\n if (!isNaN(variable.value.length)) {\n stringify += ` (length: ${variable.value.length})`;\n }\n result.push(` ${variable.name.padEnd(30)} = ${stringify}`);\n }\n return result.join('\\n');\n }\n}\n"],"file":"netcdf-reader.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"netcdf-types.js"}
|