@loaders.gl/netcdf 4.0.0-beta.2 → 4.0.0-beta.4

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.
Files changed (46) hide show
  1. package/dist/dist.dev.js +708 -0
  2. package/dist/index.cjs +919 -0
  3. package/dist/index.js +3 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/{esm/iobuffer → iobuffer}/iobuffer.js +12 -13
  6. package/dist/iobuffer/iobuffer.js.map +1 -0
  7. package/dist/{esm/netcdf-loader.js → netcdf-loader.js} +2 -2
  8. package/dist/netcdf-loader.js.map +1 -0
  9. package/dist/{esm/netcdfjs → netcdfjs}/netcdf-reader.js +12 -13
  10. package/dist/netcdfjs/netcdf-reader.js.map +1 -0
  11. package/dist/netcdfjs/netcdf-types.js.map +1 -0
  12. package/dist/{esm/netcdfjs → netcdfjs}/read-data.js +1 -1
  13. package/dist/netcdfjs/read-data.js.map +1 -0
  14. package/dist/{esm/netcdfjs → netcdfjs}/read-header.js +3 -3
  15. package/dist/netcdfjs/read-header.js.map +1 -0
  16. package/dist/{esm/netcdfjs → netcdfjs}/read-type.js +1 -1
  17. package/dist/netcdfjs/read-type.js.map +1 -0
  18. package/package.json +15 -7
  19. package/dist/es5/index.js +0 -20
  20. package/dist/es5/index.js.map +0 -1
  21. package/dist/es5/iobuffer/iobuffer.js +0 -369
  22. package/dist/es5/iobuffer/iobuffer.js.map +0 -1
  23. package/dist/es5/netcdf-loader.js +0 -77
  24. package/dist/es5/netcdf-loader.js.map +0 -1
  25. package/dist/es5/netcdfjs/netcdf-reader.js +0 -173
  26. package/dist/es5/netcdfjs/netcdf-reader.js.map +0 -1
  27. package/dist/es5/netcdfjs/netcdf-types.js +0 -2
  28. package/dist/es5/netcdfjs/netcdf-types.js.map +0 -1
  29. package/dist/es5/netcdfjs/read-data.js +0 -31
  30. package/dist/es5/netcdfjs/read-data.js.map +0 -1
  31. package/dist/es5/netcdfjs/read-header.js +0 -168
  32. package/dist/es5/netcdfjs/read-header.js.map +0 -1
  33. package/dist/es5/netcdfjs/read-type.js +0 -108
  34. package/dist/es5/netcdfjs/read-type.js.map +0 -1
  35. package/dist/esm/index.js +0 -3
  36. package/dist/esm/index.js.map +0 -1
  37. package/dist/esm/iobuffer/iobuffer.js.map +0 -1
  38. package/dist/esm/netcdf-loader.js.map +0 -1
  39. package/dist/esm/netcdfjs/LICENSE +0 -24
  40. package/dist/esm/netcdfjs/netcdf-reader.js.map +0 -1
  41. package/dist/esm/netcdfjs/netcdf-types.js.map +0 -1
  42. package/dist/esm/netcdfjs/read-data.js.map +0 -1
  43. package/dist/esm/netcdfjs/read-header.js.map +0 -1
  44. package/dist/esm/netcdfjs/read-type.js.map +0 -1
  45. /package/dist/{es5/netcdfjs → netcdfjs}/LICENSE +0 -0
  46. /package/dist/{esm/netcdfjs → netcdfjs}/netcdf-types.js +0 -0
@@ -0,0 +1,708 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if (typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if (typeof define === 'function' && define.amd) define([], factory);
5
+ else if (typeof exports === 'object') exports['loader'] = factory();
6
+ else root['loader'] = factory();})(globalThis, function () {
7
+ "use strict";
8
+ var __exports__ = (() => {
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
13
+ var __export = (target, all) => {
14
+ for (var name in all)
15
+ __defProp(target, name, { get: all[name], enumerable: true });
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+
27
+ // src/index.ts
28
+ var src_exports = {};
29
+ __export(src_exports, {
30
+ NetCDFLoader: () => NetCDFLoader,
31
+ NetCDFReader: () => NetCDFReader
32
+ });
33
+
34
+ // src/iobuffer/iobuffer.ts
35
+ var DEFAULT_BYTE_LENGTH = 1024 * 8;
36
+ var IOBuffer = class {
37
+ textDecoder = new TextDecoder();
38
+ textEncoder = new TextEncoder();
39
+ constructor(data = DEFAULT_BYTE_LENGTH, options = {}) {
40
+ let dataIsGiven = false;
41
+ if (typeof data === "number") {
42
+ data = new ArrayBuffer(data);
43
+ } else {
44
+ dataIsGiven = true;
45
+ this.lastWrittenByte = data.byteLength;
46
+ }
47
+ const offset = options.offset ? options.offset >>> 0 : 0;
48
+ const byteLength = data.byteLength - offset;
49
+ let dvOffset = offset;
50
+ if (ArrayBuffer.isView(data) || data instanceof IOBuffer) {
51
+ if (data.byteLength !== data.buffer.byteLength) {
52
+ dvOffset = data.byteOffset + offset;
53
+ }
54
+ data = data.buffer;
55
+ }
56
+ if (dataIsGiven) {
57
+ this.lastWrittenByte = byteLength;
58
+ } else {
59
+ this.lastWrittenByte = 0;
60
+ }
61
+ this.buffer = data;
62
+ this.length = byteLength;
63
+ this.byteLength = byteLength;
64
+ this.byteOffset = dvOffset;
65
+ this.offset = 0;
66
+ this.littleEndian = true;
67
+ this._data = new DataView(this.buffer, dvOffset, byteLength);
68
+ this._mark = 0;
69
+ this._marks = [];
70
+ }
71
+ available(byteLength = 1) {
72
+ return this.offset + byteLength <= this.length;
73
+ }
74
+ isLittleEndian() {
75
+ return this.littleEndian;
76
+ }
77
+ setLittleEndian() {
78
+ this.littleEndian = true;
79
+ return this;
80
+ }
81
+ isBigEndian() {
82
+ return !this.littleEndian;
83
+ }
84
+ setBigEndian() {
85
+ this.littleEndian = false;
86
+ return this;
87
+ }
88
+ skip(n = 1) {
89
+ this.offset += n;
90
+ return this;
91
+ }
92
+ seek(offset) {
93
+ this.offset = offset;
94
+ return this;
95
+ }
96
+ mark() {
97
+ this._mark = this.offset;
98
+ return this;
99
+ }
100
+ reset() {
101
+ this.offset = this._mark;
102
+ return this;
103
+ }
104
+ pushMark() {
105
+ this._marks.push(this.offset);
106
+ return this;
107
+ }
108
+ popMark() {
109
+ const offset = this._marks.pop();
110
+ if (offset === void 0) {
111
+ throw new Error("Mark stack empty");
112
+ }
113
+ this.seek(offset);
114
+ return this;
115
+ }
116
+ rewind() {
117
+ this.offset = 0;
118
+ return this;
119
+ }
120
+ ensureAvailable(byteLength = 1) {
121
+ if (!this.available(byteLength)) {
122
+ const lengthNeeded = this.offset + byteLength;
123
+ const newLength = lengthNeeded * 2;
124
+ const newArray = new Uint8Array(newLength);
125
+ newArray.set(new Uint8Array(this.buffer));
126
+ this.buffer = newArray.buffer;
127
+ this.length = this.byteLength = newLength;
128
+ this._data = new DataView(this.buffer);
129
+ }
130
+ return this;
131
+ }
132
+ readBoolean() {
133
+ return this.readUint8() !== 0;
134
+ }
135
+ readInt8() {
136
+ return this._data.getInt8(this.offset++);
137
+ }
138
+ readUint8() {
139
+ return this._data.getUint8(this.offset++);
140
+ }
141
+ readByte() {
142
+ return this.readUint8();
143
+ }
144
+ readBytes(n = 1) {
145
+ const bytes = new Uint8Array(n);
146
+ for (let i = 0; i < n; i++) {
147
+ bytes[i] = this.readByte();
148
+ }
149
+ return bytes;
150
+ }
151
+ readInt16() {
152
+ const value = this._data.getInt16(this.offset, this.littleEndian);
153
+ this.offset += 2;
154
+ return value;
155
+ }
156
+ readUint16() {
157
+ const value = this._data.getUint16(this.offset, this.littleEndian);
158
+ this.offset += 2;
159
+ return value;
160
+ }
161
+ readInt32() {
162
+ const value = this._data.getInt32(this.offset, this.littleEndian);
163
+ this.offset += 4;
164
+ return value;
165
+ }
166
+ readUint32() {
167
+ const value = this._data.getUint32(this.offset, this.littleEndian);
168
+ this.offset += 4;
169
+ return value;
170
+ }
171
+ readFloat32() {
172
+ const value = this._data.getFloat32(this.offset, this.littleEndian);
173
+ this.offset += 4;
174
+ return value;
175
+ }
176
+ readFloat64() {
177
+ const value = this._data.getFloat64(this.offset, this.littleEndian);
178
+ this.offset += 8;
179
+ return value;
180
+ }
181
+ readChar() {
182
+ return String.fromCharCode(this.readInt8());
183
+ }
184
+ readChars(n = 1) {
185
+ let result = "";
186
+ for (let i = 0; i < n; i++) {
187
+ result += this.readChar();
188
+ }
189
+ return result;
190
+ }
191
+ readUtf8(n = 1) {
192
+ return this.textDecoder.decode(this.readBytes(n));
193
+ }
194
+ writeBoolean(value) {
195
+ this.writeUint8(value ? 255 : 0);
196
+ return this;
197
+ }
198
+ writeInt8(value) {
199
+ this.ensureAvailable(1);
200
+ this._data.setInt8(this.offset++, value);
201
+ this._updateLastWrittenByte();
202
+ return this;
203
+ }
204
+ writeUint8(value) {
205
+ this.ensureAvailable(1);
206
+ this._data.setUint8(this.offset++, value);
207
+ this._updateLastWrittenByte();
208
+ return this;
209
+ }
210
+ writeByte(value) {
211
+ return this.writeUint8(value);
212
+ }
213
+ writeBytes(bytes) {
214
+ this.ensureAvailable(bytes.length);
215
+ for (let i = 0; i < bytes.length; i++) {
216
+ this._data.setUint8(this.offset++, bytes[i]);
217
+ }
218
+ this._updateLastWrittenByte();
219
+ return this;
220
+ }
221
+ writeInt16(value) {
222
+ this.ensureAvailable(2);
223
+ this._data.setInt16(this.offset, value, this.littleEndian);
224
+ this.offset += 2;
225
+ this._updateLastWrittenByte();
226
+ return this;
227
+ }
228
+ writeUint16(value) {
229
+ this.ensureAvailable(2);
230
+ this._data.setUint16(this.offset, value, this.littleEndian);
231
+ this.offset += 2;
232
+ this._updateLastWrittenByte();
233
+ return this;
234
+ }
235
+ writeInt32(value) {
236
+ this.ensureAvailable(4);
237
+ this._data.setInt32(this.offset, value, this.littleEndian);
238
+ this.offset += 4;
239
+ this._updateLastWrittenByte();
240
+ return this;
241
+ }
242
+ writeUint32(value) {
243
+ this.ensureAvailable(4);
244
+ this._data.setUint32(this.offset, value, this.littleEndian);
245
+ this.offset += 4;
246
+ this._updateLastWrittenByte();
247
+ return this;
248
+ }
249
+ writeFloat32(value) {
250
+ this.ensureAvailable(4);
251
+ this._data.setFloat32(this.offset, value, this.littleEndian);
252
+ this.offset += 4;
253
+ this._updateLastWrittenByte();
254
+ return this;
255
+ }
256
+ writeFloat64(value) {
257
+ this.ensureAvailable(8);
258
+ this._data.setFloat64(this.offset, value, this.littleEndian);
259
+ this.offset += 8;
260
+ this._updateLastWrittenByte();
261
+ return this;
262
+ }
263
+ writeChar(str) {
264
+ return this.writeUint8(str.charCodeAt(0));
265
+ }
266
+ writeChars(str) {
267
+ for (let i = 0; i < str.length; i++) {
268
+ this.writeUint8(str.charCodeAt(i));
269
+ }
270
+ return this;
271
+ }
272
+ writeUtf8(str) {
273
+ const bytes = this.textEncoder.encode(str);
274
+ return this.writeBytes(bytes);
275
+ }
276
+ toArray() {
277
+ return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte);
278
+ }
279
+ _updateLastWrittenByte() {
280
+ if (this.offset > this.lastWrittenByte) {
281
+ this.lastWrittenByte = this.offset;
282
+ }
283
+ }
284
+ };
285
+
286
+ // src/netcdfjs/read-type.ts
287
+ var TYPES = {
288
+ BYTE: 1,
289
+ CHAR: 2,
290
+ SHORT: 3,
291
+ INT: 4,
292
+ FLOAT: 5,
293
+ DOUBLE: 6
294
+ };
295
+ function readType(buffer, type, size) {
296
+ switch (type) {
297
+ case TYPES.BYTE:
298
+ return buffer.readBytes(size);
299
+ case TYPES.CHAR:
300
+ return trimNull(buffer.readChars(size));
301
+ case TYPES.SHORT:
302
+ return readNumber(size, buffer.readInt16.bind(buffer));
303
+ case TYPES.INT:
304
+ return readNumber(size, buffer.readInt32.bind(buffer));
305
+ case TYPES.FLOAT:
306
+ return readNumber(size, buffer.readFloat32.bind(buffer));
307
+ case TYPES.DOUBLE:
308
+ return readNumber(size, buffer.readFloat64.bind(buffer));
309
+ default:
310
+ throw new Error(`NetCDF: non valid type ${type}`);
311
+ }
312
+ }
313
+ function num2str(type) {
314
+ switch (Number(type)) {
315
+ case TYPES.BYTE:
316
+ return "byte";
317
+ case TYPES.CHAR:
318
+ return "char";
319
+ case TYPES.SHORT:
320
+ return "short";
321
+ case TYPES.INT:
322
+ return "int";
323
+ case TYPES.FLOAT:
324
+ return "float";
325
+ case TYPES.DOUBLE:
326
+ return "double";
327
+ default:
328
+ return "undefined";
329
+ }
330
+ }
331
+ function num2bytes(type) {
332
+ switch (Number(type)) {
333
+ case TYPES.BYTE:
334
+ return 1;
335
+ case TYPES.CHAR:
336
+ return 1;
337
+ case TYPES.SHORT:
338
+ return 2;
339
+ case TYPES.INT:
340
+ return 4;
341
+ case TYPES.FLOAT:
342
+ return 4;
343
+ case TYPES.DOUBLE:
344
+ return 8;
345
+ default:
346
+ return -1;
347
+ }
348
+ }
349
+ function str2num(type) {
350
+ switch (String(type)) {
351
+ case "byte":
352
+ return TYPES.BYTE;
353
+ case "char":
354
+ return TYPES.CHAR;
355
+ case "short":
356
+ return TYPES.SHORT;
357
+ case "int":
358
+ return TYPES.INT;
359
+ case "float":
360
+ return TYPES.FLOAT;
361
+ case "double":
362
+ return TYPES.DOUBLE;
363
+ default:
364
+ return -1;
365
+ }
366
+ }
367
+ function readNumber(size, bufferReader) {
368
+ if (size !== 1) {
369
+ const numbers = new Array(size);
370
+ for (let i = 0; i < size; i++) {
371
+ numbers[i] = bufferReader();
372
+ }
373
+ return numbers;
374
+ }
375
+ return bufferReader();
376
+ }
377
+ function trimNull(value) {
378
+ if (value.charCodeAt(value.length - 1) === 0) {
379
+ return value.substring(0, value.length - 1);
380
+ }
381
+ return value;
382
+ }
383
+
384
+ // src/netcdfjs/read-header.ts
385
+ var ZERO = 0;
386
+ var NC_DIMENSION = 10;
387
+ var NC_VARIABLE = 11;
388
+ var NC_ATTRIBUTE = 12;
389
+ var NC_UNLIMITED = 0;
390
+ function readNetCDFHeader(buffer, version) {
391
+ const recordDimensionLength = buffer.readUint32();
392
+ const dimList = readDimensionsList(buffer);
393
+ const attributes = readAttributesList(buffer);
394
+ const variableList = readVariablesList(buffer, dimList.recordId, version);
395
+ const header = {
396
+ version,
397
+ recordDimension: {
398
+ length: recordDimensionLength,
399
+ id: dimList.recordId,
400
+ name: dimList.recordName,
401
+ recordStep: variableList.recordStep
402
+ },
403
+ dimensions: dimList.dimensions,
404
+ variables: variableList.variables,
405
+ attributes
406
+ };
407
+ return header;
408
+ }
409
+ function readDimensionsList(buffer) {
410
+ const dimList = buffer.readUint32();
411
+ if (dimList === ZERO) {
412
+ if (buffer.readUint32() !== ZERO) {
413
+ throw new Error("NetCDF: wrong empty tag for list of dimensions");
414
+ }
415
+ return {
416
+ recordId: 0,
417
+ recordName: "",
418
+ dimensions: []
419
+ };
420
+ }
421
+ if (dimList !== NC_DIMENSION) {
422
+ throw new Error("NetCDF: wrong tag for list of dimensions");
423
+ }
424
+ const dimensionSize = buffer.readUint32();
425
+ const dimensions = new Array(dimensionSize);
426
+ let recordId;
427
+ let recordName;
428
+ for (let dim = 0; dim < dimensionSize; dim++) {
429
+ const name = readName(buffer);
430
+ const size = buffer.readUint32();
431
+ if (size === NC_UNLIMITED) {
432
+ recordId = dim;
433
+ recordName = name;
434
+ }
435
+ dimensions[dim] = {
436
+ name,
437
+ size
438
+ };
439
+ }
440
+ return {
441
+ dimensions,
442
+ recordId,
443
+ recordName
444
+ };
445
+ }
446
+ function readAttributesList(buffer) {
447
+ const gAttList = buffer.readUint32();
448
+ if (gAttList === ZERO) {
449
+ if (buffer.readUint32() !== ZERO) {
450
+ throw new Error("NetCDF: wrong empty tag for list of attributes");
451
+ }
452
+ return [];
453
+ }
454
+ if (gAttList !== NC_ATTRIBUTE) {
455
+ throw new Error("NetCDF: wrong tag for list of attributes");
456
+ }
457
+ const attributeSize = buffer.readUint32();
458
+ const attributes = new Array(attributeSize);
459
+ for (let gAtt = 0; gAtt < attributeSize; gAtt++) {
460
+ const name = readName(buffer);
461
+ const type = buffer.readUint32();
462
+ if (type < 1 || type > 6) {
463
+ throw new Error(`NetCDF: non valid type ${type}`);
464
+ }
465
+ const size = buffer.readUint32();
466
+ const value = readType(buffer, type, size);
467
+ padding(buffer);
468
+ attributes[gAtt] = {
469
+ name,
470
+ type: num2str(type),
471
+ value
472
+ };
473
+ }
474
+ return attributes;
475
+ }
476
+ function readVariablesList(buffer, recordId, version) {
477
+ const varList = buffer.readUint32();
478
+ let recordStep = 0;
479
+ if (varList === ZERO) {
480
+ if (buffer.readUint32() !== ZERO) {
481
+ throw new Error("NetCDF: wrong empty tag for list of variables");
482
+ }
483
+ return {
484
+ recordStep,
485
+ variables: []
486
+ };
487
+ }
488
+ if (varList !== NC_VARIABLE) {
489
+ throw new Error("NetCDF: wrong tag for list of variables");
490
+ }
491
+ const variableSize = buffer.readUint32();
492
+ const variables = new Array(variableSize);
493
+ for (let v = 0; v < variableSize; v++) {
494
+ const name = readName(buffer);
495
+ const dimensionality = buffer.readUint32();
496
+ const dimensionsIds = new Array(dimensionality);
497
+ for (let dim = 0; dim < dimensionality; dim++) {
498
+ dimensionsIds[dim] = buffer.readUint32();
499
+ }
500
+ const attributes = readAttributesList(buffer);
501
+ const type = buffer.readUint32();
502
+ if (type < 1 && type > 6) {
503
+ throw new Error(`NetCDF: non valid type ${type}`);
504
+ }
505
+ const varSize = buffer.readUint32();
506
+ let offset = buffer.readUint32();
507
+ if (version === 2) {
508
+ if (offset > 0) {
509
+ throw new Error("NetCDF: offsets larger than 4GB not supported");
510
+ }
511
+ offset = buffer.readUint32();
512
+ }
513
+ let record = false;
514
+ if (typeof recordId !== "undefined" && dimensionsIds[0] === recordId) {
515
+ recordStep += varSize;
516
+ record = true;
517
+ }
518
+ variables[v] = {
519
+ name,
520
+ dimensions: dimensionsIds,
521
+ attributes,
522
+ type: num2str(type),
523
+ size: varSize,
524
+ offset,
525
+ record
526
+ };
527
+ }
528
+ return {
529
+ variables,
530
+ recordStep
531
+ };
532
+ }
533
+ function readName(buffer) {
534
+ const nameLength = buffer.readUint32();
535
+ const name = buffer.readChars(nameLength);
536
+ padding(buffer);
537
+ return name;
538
+ }
539
+ function padding(buffer) {
540
+ if (buffer.offset % 4 !== 0) {
541
+ buffer.skip(4 - buffer.offset % 4);
542
+ }
543
+ }
544
+
545
+ // src/netcdfjs/read-data.ts
546
+ function readNonRecord(buffer, variable) {
547
+ const type = str2num(variable.type);
548
+ const size = variable.size / num2bytes(type);
549
+ const data = new Array(size);
550
+ for (let i = 0; i < size; i++) {
551
+ data[i] = readType(buffer, type, 1);
552
+ }
553
+ return data;
554
+ }
555
+ function readRecord(buffer, variable, recordDimension) {
556
+ const type = str2num(variable.type);
557
+ const width = variable.size ? variable.size / num2bytes(type) : 1;
558
+ const size = recordDimension.length;
559
+ const data = new Array(size);
560
+ const step = recordDimension.recordStep;
561
+ for (let i = 0; i < size; i++) {
562
+ const currentOffset = buffer.offset;
563
+ data[i] = readType(buffer, type, width);
564
+ buffer.seek(currentOffset + step);
565
+ }
566
+ return data;
567
+ }
568
+
569
+ // src/netcdfjs/netcdf-reader.ts
570
+ var NetCDFReader = class {
571
+ constructor(data) {
572
+ const buffer = new IOBuffer(data);
573
+ buffer.setBigEndian();
574
+ const magic = buffer.readChars(3);
575
+ if (magic !== "CDF") {
576
+ throw new Error(`NetCDF: file should start with 'CDF', found ${magic}`);
577
+ }
578
+ const version = buffer.readByte();
579
+ if (version > 2) {
580
+ throw new Error(`NetCDF: unsupported version ${version}`);
581
+ }
582
+ this.header = readNetCDFHeader(buffer, version);
583
+ this.buffer = buffer;
584
+ }
585
+ get version() {
586
+ if (this.header.version === 1) {
587
+ return "classic format";
588
+ }
589
+ return "64-bit offset format";
590
+ }
591
+ get recordDimension() {
592
+ return this.header.recordDimension;
593
+ }
594
+ get dimensions() {
595
+ return this.header.dimensions;
596
+ }
597
+ get attributes() {
598
+ return this.header.attributes;
599
+ }
600
+ get variables() {
601
+ return this.header.variables;
602
+ }
603
+ attributeExists(attributeName) {
604
+ const attribute = this.attributes.find((val) => val.name === attributeName);
605
+ return attribute !== void 0;
606
+ }
607
+ getAttribute(attributeName) {
608
+ const attribute = this.attributes.find((val) => val.name === attributeName);
609
+ if (attribute)
610
+ return attribute.value;
611
+ return null;
612
+ }
613
+ dataVariableExists(variableName) {
614
+ const variable = this.header.variables.find(function(val) {
615
+ return val.name === variableName;
616
+ });
617
+ return variable !== void 0;
618
+ }
619
+ getDataVariableAsString(variableName) {
620
+ const variable = this.getDataVariable(variableName);
621
+ if (variable)
622
+ return variable.join("");
623
+ return null;
624
+ }
625
+ getDataVariable(variableName) {
626
+ let variable;
627
+ if (typeof variableName === "string") {
628
+ variable = this.header.variables.find(function(val) {
629
+ return val.name === variableName;
630
+ });
631
+ } else {
632
+ variable = variableName;
633
+ }
634
+ if (variable === void 0) {
635
+ throw new Error(`NetCDF: variable not found: ${variableName}`);
636
+ }
637
+ this.buffer.seek(variable.offset);
638
+ if (variable.record) {
639
+ return readRecord(this.buffer, variable, this.header.recordDimension);
640
+ }
641
+ return readNonRecord(this.buffer, variable);
642
+ }
643
+ toString() {
644
+ const result = [];
645
+ result.push("DIMENSIONS");
646
+ for (const dimension of this.dimensions) {
647
+ result.push(` ${dimension.name.padEnd(30)} = size: ${dimension.size}`);
648
+ }
649
+ result.push("");
650
+ result.push("GLOBAL ATTRIBUTES");
651
+ for (const attribute of this.attributes) {
652
+ result.push(` ${attribute.name.padEnd(30)} = ${attribute.value}`);
653
+ }
654
+ const variables = JSON.parse(JSON.stringify(this.variables));
655
+ result.push("");
656
+ result.push("VARIABLES:");
657
+ for (const variable of variables) {
658
+ variable.value = this.getDataVariable(variable);
659
+ let stringify = JSON.stringify(variable.value);
660
+ if (stringify.length > 50)
661
+ stringify = stringify.substring(0, 50);
662
+ if (!isNaN(variable.value.length)) {
663
+ stringify += ` (length: ${variable.value.length})`;
664
+ }
665
+ result.push(` ${variable.name.padEnd(30)} = ${stringify}`);
666
+ }
667
+ return result.join("\n");
668
+ }
669
+ };
670
+
671
+ // src/netcdf-loader.ts
672
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
673
+ var NetCDFWorkerLoader = {
674
+ name: "NetCDF",
675
+ id: "mvt",
676
+ module: "mvt",
677
+ version: VERSION,
678
+ extensions: ["cdf", "nc"],
679
+ mimeTypes: ["application/netcdf", "application/x-netcdf"],
680
+ category: "image",
681
+ options: {
682
+ netcdf: {
683
+ loadVariables: false
684
+ }
685
+ }
686
+ };
687
+ var NetCDFLoader = {
688
+ ...NetCDFWorkerLoader,
689
+ parse: async (arrayBuffer, options) => parseNetCDF(arrayBuffer, options),
690
+ binary: true
691
+ };
692
+ function parseNetCDF(arrayBuffer, options) {
693
+ const reader = new NetCDFReader(arrayBuffer);
694
+ const variables = {};
695
+ if (options?.netcdf?.loadData) {
696
+ for (const variable of reader.variables) {
697
+ variables[variable.name] = reader.getDataVariable(variable);
698
+ }
699
+ }
700
+ return {
701
+ loaderData: reader.header,
702
+ data: variables
703
+ };
704
+ }
705
+ return __toCommonJS(src_exports);
706
+ })();
707
+ return __exports__;
708
+ });