@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.
Files changed (50) hide show
  1. package/dist/index.js +3 -7
  2. package/dist/index.js.map +1 -0
  3. package/dist/iobuffer/iobuffer.js +370 -425
  4. package/dist/iobuffer/iobuffer.js.map +1 -0
  5. package/dist/netcdf-loader.js +36 -46
  6. package/dist/netcdf-loader.js.map +1 -0
  7. package/dist/{es5/netcdfjs → netcdfjs}/LICENSE +0 -0
  8. package/dist/netcdfjs/netcdf-reader.js +126 -155
  9. package/dist/netcdfjs/netcdf-reader.js.map +1 -0
  10. package/dist/netcdfjs/netcdf-types.js +2 -2
  11. package/dist/{es5/netcdfjs → netcdfjs}/netcdf-types.js.map +0 -0
  12. package/dist/netcdfjs/read-data.js +26 -47
  13. package/dist/netcdfjs/read-data.js.map +1 -0
  14. package/dist/netcdfjs/read-header.js +173 -206
  15. package/dist/netcdfjs/read-header.js.map +1 -0
  16. package/dist/netcdfjs/read-type.js +117 -130
  17. package/dist/netcdfjs/read-type.js.map +1 -0
  18. package/package.json +5 -5
  19. package/dist/es5/index.js +0 -22
  20. package/dist/es5/index.js.map +0 -1
  21. package/dist/es5/iobuffer/iobuffer.js +0 -432
  22. package/dist/es5/iobuffer/iobuffer.js.map +0 -1
  23. package/dist/es5/netcdf-loader.js +0 -105
  24. package/dist/es5/netcdf-loader.js.map +0 -1
  25. package/dist/es5/netcdfjs/netcdf-reader.js +0 -207
  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/read-data.js +0 -38
  29. package/dist/es5/netcdfjs/read-data.js.map +0 -1
  30. package/dist/es5/netcdfjs/read-header.js +0 -207
  31. package/dist/es5/netcdfjs/read-header.js.map +0 -1
  32. package/dist/es5/netcdfjs/read-type.js +0 -142
  33. package/dist/es5/netcdfjs/read-type.js.map +0 -1
  34. package/dist/esm/index.js +0 -3
  35. package/dist/esm/index.js.map +0 -1
  36. package/dist/esm/iobuffer/iobuffer.js +0 -372
  37. package/dist/esm/iobuffer/iobuffer.js.map +0 -1
  38. package/dist/esm/netcdf-loader.js +0 -42
  39. package/dist/esm/netcdf-loader.js.map +0 -1
  40. package/dist/esm/netcdfjs/LICENSE +0 -24
  41. package/dist/esm/netcdfjs/netcdf-reader.js +0 -136
  42. package/dist/esm/netcdfjs/netcdf-reader.js.map +0 -1
  43. package/dist/esm/netcdfjs/netcdf-types.js +0 -2
  44. package/dist/esm/netcdfjs/netcdf-types.js.map +0 -1
  45. package/dist/esm/netcdfjs/read-data.js +0 -28
  46. package/dist/esm/netcdfjs/read-data.js.map +0 -1
  47. package/dist/esm/netcdfjs/read-header.js +0 -197
  48. package/dist/esm/netcdfjs/read-header.js.map +0 -1
  49. package/dist/esm/netcdfjs/read-type.js +0 -127
  50. package/dist/esm/netcdfjs/read-type.js.map +0 -1
@@ -0,0 +1 @@
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,GAAuBN,IAAI,CAACO,UAA5B;AACD;;AAED,UAAMC,MAAM,GAAGP,OAAO,CAACO,MAAR,GAAiBP,OAAO,CAACO,MAAR,KAAmB,CAApC,GAAwC,CAAvD;AACA,UAAMD,UAAU,GAAGP,IAAI,CAACO,UAAL,GAAkBC,MAArC;AACA,QAAIC,QAAQ,GAAGD,MAAf;;AACA,QAAIH,WAAW,CAACK,MAAZ,CAAmBV,IAAnB,KAA4BA,IAAI,YAAYF,QAAhD,EAA0D;AACxD,UAAIE,IAAI,CAACO,UAAL,KAAoBP,IAAI,CAACW,MAAL,CAAYJ,UAApC,EAAgD;AAC9CE,QAAAA,QAAQ,GAAGT,IAAI,CAACY,UAAL,GAAkBJ,MAA7B;AACD;;AACDR,MAAAA,IAAI,GAAGA,IAAI,CAACW,MAAZ;AACD;;AACD,QAAIP,WAAJ,EAAiB;AACf,WAAKE,eAAL,GAAuBC,UAAvB;AACD,KAFD,MAEO;AACL,WAAKD,eAAL,GAAuB,CAAvB;AACD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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,52 +1,42 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._typecheckNetCDFLoader = exports._typecheckNetCDFWorkerLoader = exports.NetCDFLoader = exports.NetCDFWorkerLoader = void 0;
4
- const netcdf_reader_1 = require("./netcdfjs/netcdf-reader");
5
- // __VERSION__ is injected by babel-plugin-version-inline
6
- // @ts-ignore TS2304: Cannot find name '__VERSION__'.
7
- const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
8
- /**
9
- * Worker loader for NETCDF
10
- */
11
- exports.NetCDFWorkerLoader = {
12
- name: 'NetCDF',
13
- id: 'mvt',
14
- module: 'mvt',
15
- version: VERSION,
16
- extensions: ['cdf', 'nc'],
17
- mimeTypes: [
18
- 'application/netcdf',
19
- 'application/x-netcdf'
20
- // 'application/octet-stream'
21
- ],
22
- category: 'image',
23
- options: {
24
- netcdf: {
25
- loadVariables: false
26
- }
1
+ import { NetCDFReader } from './netcdfjs/netcdf-reader';
2
+ const VERSION = typeof "4.0.0-alpha.5" !== 'undefined' ? "4.0.0-alpha.5" : '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
27
14
  }
15
+ }
28
16
  };
29
- /**
30
- * Loader for the NetCDF format
31
- */
32
- exports.NetCDFLoader = {
33
- ...exports.NetCDFWorkerLoader,
34
- parse: async (arrayBuffer, options) => parseNetCDF(arrayBuffer, options),
35
- binary: true
17
+ export const NetCDFLoader = { ...NetCDFWorkerLoader,
18
+ parse: async (arrayBuffer, options) => parseNetCDF(arrayBuffer, options),
19
+ binary: true
36
20
  };
21
+
37
22
  function parseNetCDF(arrayBuffer, options) {
38
- const reader = new netcdf_reader_1.NetCDFReader(arrayBuffer);
39
- const variables = {};
40
- if (options?.netcdf?.loadData) {
41
- for (const variable of reader.variables) {
42
- variables[variable.name] = reader.getDataVariable(variable);
43
- }
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);
44
31
  }
45
- return {
46
- loaderData: reader.header,
47
- data: variables
48
- };
32
+ }
33
+
34
+ return {
35
+ loaderData: reader.header,
36
+ data: variables
37
+ };
49
38
  }
50
- // Type tests
51
- exports._typecheckNetCDFWorkerLoader = exports.NetCDFWorkerLoader;
52
- exports._typecheckNetCDFLoader = exports.NetCDFLoader;
39
+
40
+ export const _typecheckNetCDFWorkerLoader = NetCDFWorkerLoader;
41
+ export const _typecheckNetCDFLoader = NetCDFLoader;
42
+ //# sourceMappingURL=netcdf-loader.js.map
@@ -0,0 +1 @@
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,2BAAuB,WAAvB,qBAAmD,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"}
File without changes
@@ -1,165 +1,136 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NetCDFReader = void 0;
4
- const iobuffer_1 = require("../iobuffer/iobuffer");
5
- const read_header_1 = require("./read-header");
6
- const read_data_1 = require("./read-data");
7
- /**
8
- * Reads a NetCDF v3.x file
9
- * https://www.unidata.ucar.edu/software/netcdf/docs/file_format_specifications.html
10
- * @param {ArrayBuffer} data - ArrayBuffer or any Typed Array (including Node.js' Buffer from v4) with the data
11
- * @constructor
12
- */
13
- class NetCDFReader {
14
- constructor(data) {
15
- const buffer = new iobuffer_1.IOBuffer(data);
16
- buffer.setBigEndian();
17
- // Validate that it's a NetCDF file
18
- const magic = buffer.readChars(3);
19
- if (magic !== 'CDF') {
20
- throw new Error(`NetCDF: file should start with 'CDF', found ${magic}`);
21
- }
22
- // Check the NetCDF format
23
- const version = buffer.readByte();
24
- if (version > 2) {
25
- throw new Error(`NetCDF: unsupported version ${version}`);
26
- }
27
- // Read the header
28
- this.header = (0, read_header_1.readNetCDFHeader)(buffer, version);
29
- this.buffer = buffer;
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));
30
17
  }
31
- /**
32
- * @return {string} - Version for the NetCDF format
33
- */
34
- get version() {
35
- if (this.header.version === 1) {
36
- return 'classic format';
37
- }
38
- return '64-bit offset format';
18
+
19
+ const version = buffer.readByte();
20
+
21
+ if (version > 2) {
22
+ throw new Error("NetCDF: unsupported version ".concat(version));
39
23
  }
40
- /**
41
- * Get metadata for the record dimension
42
- */
43
- get recordDimension() {
44
- return this.header.recordDimension;
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';
45
32
  }
46
- /**
47
- * Get list of dimensions (each with `name` and `size`)
48
- */
49
- get dimensions() {
50
- return this.header.dimensions;
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;
51
86
  }
52
- /**
53
- * Get list of global attributes with:
54
- * * `name`: String with the name of the attribute
55
- * * `type`: String with the type of the attribute
56
- * * `value`: A number or string with the value of the attribute
57
- */
58
- get attributes() {
59
- return this.header.attributes;
87
+
88
+ if (variable === undefined) {
89
+ throw new Error("NetCDF: variable not found: ".concat(variableName));
60
90
  }
61
- /**
62
- * Get list of variables
63
- */
64
- get variables() {
65
- return this.header.variables;
91
+
92
+ this.buffer.seek(variable.offset);
93
+
94
+ if (variable.record) {
95
+ return readRecord(this.buffer, variable, this.header.recordDimension);
66
96
  }
67
- /**
68
- * Check if an attribute exists
69
- * @param attributeName - Name of the attribute to find
70
- * @return
71
- */
72
- attributeExists(attributeName) {
73
- const attribute = this.attributes.find((val) => val.name === attributeName);
74
- return attribute !== undefined;
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));
75
107
  }
76
- /**
77
- * Returns the value of an attribute
78
- * @param attributeName
79
- * @return Value of the attributeName or null
80
- */
81
- getAttribute(attributeName) {
82
- const attribute = this.attributes.find((val) => val.name === attributeName);
83
- if (attribute)
84
- return attribute.value;
85
- return null;
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));
86
114
  }
87
- /**
88
- * Check if a dataVariable exists
89
- * @param variableName - Name of the variable to find
90
- * @return
91
- */
92
- dataVariableExists(variableName) {
93
- const variable = this.header.variables.find(function (val) {
94
- return val.name === variableName;
95
- });
96
- return variable !== undefined;
97
- }
98
- /**
99
- * Returns the value of a variable as a string
100
- * @param variableName
101
- * @return Value of the variable as a string or null
102
- */
103
- getDataVariableAsString(variableName) {
104
- const variable = this.getDataVariable(variableName);
105
- if (variable)
106
- return variable.join('');
107
- return null;
108
- }
109
- /**
110
- * Retrieves the data for a given variable
111
- * @param variableName - Name of the variable to search or variable object
112
- * @return List with the variable values
113
- */
114
- getDataVariable(variableName) {
115
- let variable;
116
- if (typeof variableName === 'string') {
117
- // search the variable
118
- variable = this.header.variables.find(function (val) {
119
- return val.name === variableName;
120
- });
121
- }
122
- else {
123
- variable = variableName;
124
- }
125
- // throws if variable not found
126
- if (variable === undefined) {
127
- throw new Error(`NetCDF: variable not found: ${variableName}`);
128
- }
129
- // go to the offset position
130
- this.buffer.seek(variable.offset);
131
- if (variable.record) {
132
- // record variable case
133
- return (0, read_data_1.readRecord)(this.buffer, variable, this.header.recordDimension);
134
- }
135
- // non-record variable case
136
- return (0, read_data_1.readNonRecord)(this.buffer, variable);
137
- }
138
- toString() {
139
- const result = [];
140
- result.push('DIMENSIONS');
141
- for (const dimension of this.dimensions) {
142
- result.push(` ${dimension.name.padEnd(30)} = size: ${dimension.size}`);
143
- }
144
- result.push('');
145
- result.push('GLOBAL ATTRIBUTES');
146
- for (const attribute of this.attributes) {
147
- result.push(` ${attribute.name.padEnd(30)} = ${attribute.value}`);
148
- }
149
- const variables = JSON.parse(JSON.stringify(this.variables));
150
- result.push('');
151
- result.push('VARIABLES:');
152
- for (const variable of variables) {
153
- variable.value = this.getDataVariable(variable);
154
- let stringify = JSON.stringify(variable.value);
155
- if (stringify.length > 50)
156
- stringify = stringify.substring(0, 50);
157
- if (!isNaN(variable.value.length)) {
158
- stringify += ` (length: ${variable.value.length})`;
159
- }
160
- result.push(` ${variable.name.padEnd(30)} = ${stringify}`);
161
- }
162
- return result.join('\n');
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));
163
130
  }
131
+
132
+ return result.join('\n');
133
+ }
134
+
164
135
  }
165
- exports.NetCDFReader = NetCDFReader;
136
+ //# sourceMappingURL=netcdf-reader.js.map
@@ -0,0 +1 @@
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,eAA/B;AACA,SAAQC,UAAR,EAAoBC,aAApB,QAAwC,aAAxC;AAQA,OAAO,MAAMC,YAAN,CAAmB;AAIxBC,EAAAA,WAAW,CAACC,IAAD,EAAO;AAAA;;AAAA;;AAChB,UAAMC,MAAM,GAAG,IAAIP,QAAJ,CAAaM,IAAb,CAAf;AACAC,IAAAA,MAAM,CAACC,YAAP;AAGA,UAAMC,KAAK,GAAGF,MAAM,CAACG,SAAP,CAAiB,CAAjB,CAAd;;AACA,QAAID,KAAK,KAAK,KAAd,EAAqB;AACnB,YAAM,IAAIE,KAAJ,uDAAyDF,KAAzD,EAAN;AACD;;AAGD,UAAMG,OAAO,GAAGL,MAAM,CAACM,QAAP,EAAhB;;AACA,QAA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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,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
2
+ //# sourceMappingURL=netcdf-types.js.map
@@ -1,49 +1,28 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readRecord = exports.readNonRecord = void 0;
4
- const read_type_1 = require("./read-type");
5
- // const STREAMING = 4294967295;
6
- /**
7
- * Read data for the given non-record variable
8
- * @param buffer - Buffer for the file data
9
- * @param variable - Variable metadata
10
- * @return Data of the element
11
- */
12
- function readNonRecord(buffer, variable) {
13
- // variable type
14
- const type = (0, read_type_1.str2num)(variable.type);
15
- // size of the data
16
- const size = variable.size / (0, read_type_1.num2bytes)(type);
17
- // iterates over the data
18
- const data = new Array(size);
19
- for (let i = 0; i < size; i++) {
20
- data[i] = (0, read_type_1.readType)(buffer, type, 1);
21
- }
22
- return data;
1
+ import { readType, str2num, num2bytes } from './read-type';
2
+ export function readNonRecord(buffer, variable) {
3
+ const type = str2num(variable.type);
4
+ const size = variable.size / num2bytes(type);
5
+ const data = new Array(size);
6
+
7
+ for (let i = 0; i < size; i++) {
8
+ data[i] = readType(buffer, type, 1);
9
+ }
10
+
11
+ return data;
23
12
  }
24
- exports.readNonRecord = readNonRecord;
25
- /**
26
- * Read data for the given record variable
27
- * @param buffer - Buffer for the file data
28
- * @param variable - Variable metadata
29
- * @param recordDimension - Record dimension metadata
30
- * @return - Data of the element
31
- */
32
- function readRecord(buffer, variable, recordDimension) {
33
- // variable type
34
- const type = (0, read_type_1.str2num)(variable.type);
35
- const width = variable.size ? variable.size / (0, read_type_1.num2bytes)(type) : 1;
36
- // size of the data
37
- // TODO streaming data
38
- const size = recordDimension.length;
39
- // iterates over the data
40
- const data = new Array(size);
41
- const step = recordDimension.recordStep;
42
- for (let i = 0; i < size; i++) {
43
- const currentOffset = buffer.offset;
44
- data[i] = (0, read_type_1.readType)(buffer, type, width);
45
- buffer.seek(currentOffset + step);
46
- }
47
- return data;
13
+ export function readRecord(buffer, variable, recordDimension) {
14
+ const type = str2num(variable.type);
15
+ const width = variable.size ? variable.size / num2bytes(type) : 1;
16
+ const size = recordDimension.length;
17
+ const data = new Array(size);
18
+ const step = recordDimension.recordStep;
19
+
20
+ for (let i = 0; i < size; i++) {
21
+ const currentOffset = buffer.offset;
22
+ data[i] = readType(buffer, type, width);
23
+ buffer.seek(currentOffset + step);
24
+ }
25
+
26
+ return data;
48
27
  }
49
- exports.readRecord = readRecord;
28
+ //# sourceMappingURL=read-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/netcdfjs/read-data.ts"],"names":["readType","str2num","num2bytes","readNonRecord","buffer","variable","type","size","data","Array","i","readRecord","recordDimension","width","length","step","recordStep","currentOffset","offset","seek"],"mappings":"AAEA,SAAQA,QAAR,EAAkBC,OAAlB,EAA2BC,SAA3B,QAA2C,aAA3C;AAUA,OAAO,SAASC,aAAT,CACLC,MADK,EAELC,QAFK,EAGwC;AAE7C,QAAMC,IAAI,GAAGL,OAAO,CAACI,QAAQ,CAACC,IAAV,CAApB;AAGA,QAAMC,IAAI,GAAGF,QAAQ,CAACE,IAAT,GAAgBL,SAAS,CAACI,IAAD,CAAtC;AAGA,QAAME,IAAI,GAAG,IAAIC,KAAJ,CAAUF,IAAV,CAAb;;AACA,OAAK,IAAIG,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGH,IAApB,EAA0BG,CAAC,EAA3B,EAA+B;AAC7BF,IAAAA,IAAI,CAACE,CAAD,CAAJ,GAAUV,QAAQ,CAACI,MAAD,EAASE,IAAT,EAAe,CAAf,CAAlB;AACD;;AAED,SAAOE,IAAP;AACD;AASD,OAAO,SAASG,UAAT,CACLP,MADK,EAELC,QAFK,EAGLO,eAHK,EAIwC;AAE7C,QAAMN,IAAI,GAAGL,OAAO,CAACI,QAAQ,CAACC,IAAV,CAApB;AACA,QAAMO,KAAK,GAAGR,QAAQ,CAACE,IAAT,GAAgBF,QAAQ,CAACE,IAAT,GAAgBL,SAAS,CAACI,IAAD,CAAzC,GAAkD,CAAhE;AAIA,QAAMC,IAAI,GAAGK,eAAe,CAACE,MAA7B;AAGA,QAAMN,IAAI,GAAG,IAAIC,KAAJ,CAAUF,IAAV,CAAb;AACA,QAAMQ,IAAI,GAAGH,eAAe,CAACI,UAA7B;;AAEA,OAAK,IAAIN,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGH,IAApB,EAA0BG,CAAC,EAA3B,EAA+B;AAC7B,UAAMO,aAAa,GAAGb,MAAM,CAACc,MAA7B;AACAV,IAAAA,IAAI,CAACE,CAAD,CAAJ,GAAUV,QAAQ,CAACI,MAAD,EAASE,IAAT,EAAeO,KAAf,CAAlB;AACAT,IAAAA,MAAM,CAACe,IAAP,CAAYF,aAAa,GAAGF,IAA5B;AACD;;AAED,SAAOP,IAAP;AACD","sourcesContent":["import type {IOBuffer} from '../iobuffer/iobuffer';\nimport type {NetCDFRecordDimension, NetCDFVariable} from './netcdf-types';\nimport {readType, str2num, num2bytes} from './read-type';\n\n// const STREAMING = 4294967295;\n\n/**\n * Read data for the given non-record variable\n * @param buffer - Buffer for the file data\n * @param variable - Variable metadata\n * @return Data of the element\n */\nexport function readNonRecord(\n buffer: IOBuffer,\n variable: NetCDFVariable\n): (string | number | number[] | Uint8Array)[] {\n // variable type\n const type = str2num(variable.type);\n\n // size of the data\n const size = variable.size / num2bytes(type);\n\n // iterates over the data\n const data = new Array(size);\n for (let i = 0; i < size; i++) {\n data[i] = readType(buffer, type, 1);\n }\n\n return data;\n}\n\n/**\n * Read data for the given record variable\n * @param buffer - Buffer for the file data\n * @param variable - Variable metadata\n * @param recordDimension - Record dimension metadata\n * @return - Data of the element\n */\nexport function readRecord(\n buffer: IOBuffer,\n variable: NetCDFVariable,\n recordDimension: NetCDFRecordDimension\n): (string | number | number[] | Uint8Array)[] {\n // variable type\n const type = str2num(variable.type);\n const width = variable.size ? variable.size / num2bytes(type) : 1;\n\n // size of the data\n // TODO streaming data\n const size = recordDimension.length;\n\n // iterates over the data\n const data = new Array(size);\n const step = recordDimension.recordStep;\n\n for (let i = 0; i < size; i++) {\n const currentOffset = buffer.offset;\n data[i] = readType(buffer, type, width);\n buffer.seek(currentOffset + step);\n }\n\n return data;\n}\n"],"file":"read-data.js"}