@loaders.gl/netcdf 4.0.0-alpha.5 → 4.0.0-alpha.7

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 (57) hide show
  1. package/dist/es5/index.js +20 -0
  2. package/dist/es5/index.js.map +1 -0
  3. package/dist/es5/iobuffer/iobuffer.js +369 -0
  4. package/dist/es5/iobuffer/iobuffer.js.map +1 -0
  5. package/dist/es5/netcdf-loader.js +81 -0
  6. package/dist/es5/netcdf-loader.js.map +1 -0
  7. package/dist/es5/netcdfjs/netcdf-reader.js +173 -0
  8. package/dist/es5/netcdfjs/netcdf-reader.js.map +1 -0
  9. package/dist/es5/netcdfjs/netcdf-types.js +2 -0
  10. package/dist/es5/netcdfjs/netcdf-types.js.map +1 -0
  11. package/dist/es5/netcdfjs/read-data.js +31 -0
  12. package/dist/es5/netcdfjs/read-data.js.map +1 -0
  13. package/dist/es5/netcdfjs/read-header.js +168 -0
  14. package/dist/es5/netcdfjs/read-header.js.map +1 -0
  15. package/dist/es5/netcdfjs/read-type.js +108 -0
  16. package/dist/es5/netcdfjs/read-type.js.map +1 -0
  17. package/dist/esm/index.js +3 -0
  18. package/dist/esm/index.js.map +1 -0
  19. package/dist/esm/iobuffer/iobuffer.js +270 -0
  20. package/dist/esm/iobuffer/iobuffer.js.map +1 -0
  21. package/dist/esm/netcdf-loader.js +38 -0
  22. package/dist/esm/netcdf-loader.js.map +1 -0
  23. package/dist/esm/netcdfjs/LICENSE +24 -0
  24. package/dist/esm/netcdfjs/netcdf-reader.js +104 -0
  25. package/dist/esm/netcdfjs/netcdf-reader.js.map +1 -0
  26. package/dist/esm/netcdfjs/netcdf-types.js +2 -0
  27. package/dist/esm/netcdfjs/netcdf-types.js.map +1 -0
  28. package/dist/esm/netcdfjs/read-data.js +24 -0
  29. package/dist/esm/netcdfjs/read-data.js.map +1 -0
  30. package/dist/esm/netcdfjs/read-header.js +161 -0
  31. package/dist/esm/netcdfjs/read-header.js.map +1 -0
  32. package/dist/esm/netcdfjs/read-type.js +97 -0
  33. package/dist/esm/netcdfjs/read-type.js.map +1 -0
  34. package/dist/index.js +7 -3
  35. package/dist/iobuffer/iobuffer.d.ts +1 -1
  36. package/dist/iobuffer/iobuffer.d.ts.map +1 -1
  37. package/dist/iobuffer/iobuffer.js +425 -370
  38. package/dist/netcdf-loader.d.ts +2 -2
  39. package/dist/netcdf-loader.d.ts.map +1 -1
  40. package/dist/netcdf-loader.js +46 -36
  41. package/dist/netcdfjs/netcdf-reader.js +155 -126
  42. package/dist/netcdfjs/netcdf-types.d.ts +5 -5
  43. package/dist/netcdfjs/netcdf-types.d.ts.map +1 -1
  44. package/dist/netcdfjs/netcdf-types.js +2 -2
  45. package/dist/netcdfjs/read-data.js +47 -26
  46. package/dist/netcdfjs/read-header.js +206 -173
  47. package/dist/netcdfjs/read-type.js +130 -117
  48. package/package.json +5 -5
  49. package/dist/index.js.map +0 -1
  50. package/dist/iobuffer/iobuffer.js.map +0 -1
  51. package/dist/netcdf-loader.js.map +0 -1
  52. package/dist/netcdfjs/netcdf-reader.js.map +0 -1
  53. package/dist/netcdfjs/netcdf-types.js.map +0 -1
  54. package/dist/netcdfjs/read-data.js.map +0 -1
  55. package/dist/netcdfjs/read-header.js.map +0 -1
  56. package/dist/netcdfjs/read-type.js.map +0 -1
  57. /package/dist/{netcdfjs → es5/netcdfjs}/LICENSE +0 -0
@@ -1,12 +1,12 @@
1
1
  import type { Loader, LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
2
2
  import type { NetCDFHeader } from './netcdfjs/netcdf-types';
3
- export declare type NetCDF = {
3
+ export type NetCDF = {
4
4
  loaderData: NetCDFHeader;
5
5
  data: {
6
6
  [variableName: string]: any[][];
7
7
  };
8
8
  };
9
- export declare type NetCDFLoaderOptions = LoaderOptions & {
9
+ export type NetCDFLoaderOptions = LoaderOptions & {
10
10
  netcdf?: {
11
11
  loadData?: boolean;
12
12
  };
@@ -1 +1 @@
1
- {"version":3,"file":"netcdf-loader.d.ts","sourceRoot":"","sources":["../src/netcdf-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACtF,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,yBAAyB,CAAC;AAO1D,oBAAY,MAAM,GAAG;IACnB,UAAU,EAAE,YAAY,CAAC;IACzB,IAAI,EAAE;QAAC,CAAC,YAAY,EAAE,MAAM,GAAG,GAAG,EAAE,EAAE,CAAA;KAAC,CAAC;CACzC,CAAC;AAEF,oBAAY,mBAAmB,GAAG,aAAa,GAAG;IAChD,MAAM,CAAC,EAAE;QACP,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;CAiB9B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;CAIxB,CAAC;AAiBF,eAAO,MAAM,4BAA4B,EAAE,MAA2B,CAAC;AACvE,eAAO,MAAM,sBAAsB,EAAE,gBAA+B,CAAC"}
1
+ {"version":3,"file":"netcdf-loader.d.ts","sourceRoot":"","sources":["../src/netcdf-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACtF,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,yBAAyB,CAAC;AAO1D,MAAM,MAAM,MAAM,GAAG;IACnB,UAAU,EAAE,YAAY,CAAC;IACzB,IAAI,EAAE;QAAC,CAAC,YAAY,EAAE,MAAM,GAAG,GAAG,EAAE,EAAE,CAAA;KAAC,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,aAAa,GAAG;IAChD,MAAM,CAAC,EAAE;QACP,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;CAiB9B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;CAIxB,CAAC;AAiBF,eAAO,MAAM,4BAA4B,EAAE,MAA2B,CAAC;AACvE,eAAO,MAAM,sBAAsB,EAAE,gBAA+B,CAAC"}
@@ -1,42 +1,52 @@
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
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
+ }
14
27
  }
15
- }
16
28
  };
17
- export const NetCDFLoader = { ...NetCDFWorkerLoader,
18
- parse: async (arrayBuffer, options) => parseNetCDF(arrayBuffer, options),
19
- binary: true
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
20
36
  };
21
-
22
37
  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);
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
+ }
31
44
  }
32
- }
33
-
34
- return {
35
- loaderData: reader.header,
36
- data: variables
37
- };
45
+ return {
46
+ loaderData: reader.header,
47
+ data: variables
48
+ };
38
49
  }
39
-
40
- export const _typecheckNetCDFWorkerLoader = NetCDFWorkerLoader;
41
- export const _typecheckNetCDFLoader = NetCDFLoader;
42
- //# sourceMappingURL=netcdf-loader.js.map
50
+ // Type tests
51
+ exports._typecheckNetCDFWorkerLoader = exports.NetCDFWorkerLoader;
52
+ exports._typecheckNetCDFLoader = exports.NetCDFLoader;
@@ -1,136 +1,165 @@
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));
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;
17
30
  }
18
-
19
- const version = buffer.readByte();
20
-
21
- if (version > 2) {
22
- throw new Error("NetCDF: unsupported version ".concat(version));
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';
23
39
  }
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';
40
+ /**
41
+ * Get metadata for the record dimension
42
+ */
43
+ get recordDimension() {
44
+ return this.header.recordDimension;
32
45
  }
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;
46
+ /**
47
+ * Get list of dimensions (each with `name` and `size`)
48
+ */
49
+ get dimensions() {
50
+ return this.header.dimensions;
86
51
  }
87
-
88
- if (variable === undefined) {
89
- throw new Error("NetCDF: variable not found: ".concat(variableName));
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;
90
60
  }
91
-
92
- this.buffer.seek(variable.offset);
93
-
94
- if (variable.record) {
95
- return readRecord(this.buffer, variable, this.header.recordDimension);
61
+ /**
62
+ * Get list of variables
63
+ */
64
+ get variables() {
65
+ return this.header.variables;
96
66
  }
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));
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;
107
75
  }
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));
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;
114
86
  }
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));
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');
130
163
  }
131
-
132
- return result.join('\n');
133
- }
134
-
135
164
  }
136
- //# sourceMappingURL=netcdf-reader.js.map
165
+ exports.NetCDFReader = NetCDFReader;
@@ -5,7 +5,7 @@
5
5
  * @param attributes: List of global attributes
6
6
  * @param variables: List of variables
7
7
  */
8
- export declare type NetCDFHeader = {
8
+ export type NetCDFHeader = {
9
9
  version: number;
10
10
  recordDimension: NetCDFRecordDimension;
11
11
  dimensions: NetCDFDimension[];
@@ -19,7 +19,7 @@ export declare type NetCDFHeader = {
19
19
  * @param name name of the record dimension
20
20
  * @param recordStep the record variables step size
21
21
  */
22
- export declare type NetCDFRecordDimension = {
22
+ export type NetCDFRecordDimension = {
23
23
  length: number;
24
24
  id: number;
25
25
  name: string;
@@ -32,7 +32,7 @@ export declare type NetCDFRecordDimension = {
32
32
  * @param recordId: id of the dimension that has unlimited size or undefined,
33
33
  * @param recordName: name of the dimension that has unlimited size
34
34
  */
35
- export declare type NetCDFDimension = {
35
+ export type NetCDFDimension = {
36
36
  name: string;
37
37
  size: number;
38
38
  recordId: number;
@@ -48,7 +48,7 @@ export declare type NetCDFDimension = {
48
48
  * @param offset Number with the offset where of the variable begins
49
49
  * @param record True if is a record variable, false otherwise (unlimited size)
50
50
  */
51
- export declare type NetCDFVariable = {
51
+ export type NetCDFVariable = {
52
52
  name: string;
53
53
  dimensions: [];
54
54
  attributes: [];
@@ -62,7 +62,7 @@ export declare type NetCDFVariable = {
62
62
  * @param type type of the attribute
63
63
  * @param value number or string with the value of the attribute
64
64
  */
65
- export declare type NetCDFAttribute = {
65
+ export type NetCDFAttribute = {
66
66
  name: string;
67
67
  type: string;
68
68
  value: string;
@@ -1 +1 @@
1
- {"version":3,"file":"netcdf-types.d.ts","sourceRoot":"","sources":["../../src/netcdfjs/netcdf-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,oBAAY,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,qBAAqB,CAAC;IACvC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,SAAS,EAAE,cAAc,EAAE,CAAC;CAC7B,CAAC;AAEF;;;;;;GAMG;AACH,oBAAY,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;GAMG;AACH,oBAAY,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;GASG;AACH,oBAAY,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,EAAE,CAAC;IACf,UAAU,EAAE,EAAE,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;;;GAIG;AACH,oBAAY,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC"}
1
+ {"version":3,"file":"netcdf-types.d.ts","sourceRoot":"","sources":["../../src/netcdfjs/netcdf-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,qBAAqB,CAAC;IACvC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,SAAS,EAAE,cAAc,EAAE,CAAC;CAC7B,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,EAAE,CAAC;IACf,UAAU,EAAE,EAAE,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC"}
@@ -1,2 +1,2 @@
1
- export {};
2
- //# sourceMappingURL=netcdf-types.js.map
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,28 +1,49 @@
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;
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;
12
23
  }
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;
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;
27
48
  }
28
- //# sourceMappingURL=read-data.js.map
49
+ exports.readRecord = readRecord;