@loaders.gl/netcdf 4.2.0-alpha.4 → 4.2.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +284 -9
- package/dist/dist.min.js +10 -0
- package/dist/index.cjs +48 -14
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/iobuffer/iobuffer.js +445 -266
- package/dist/netcdf-loader.d.ts +1 -1
- package/dist/netcdf-loader.d.ts.map +1 -1
- package/dist/netcdf-loader.js +37 -27
- package/dist/netcdfjs/netcdf-reader.d.ts +2 -2
- package/dist/netcdfjs/netcdf-reader.d.ts.map +1 -1
- package/dist/netcdfjs/netcdf-reader.js +156 -89
- package/dist/netcdfjs/netcdf-types.js +0 -1
- package/dist/netcdfjs/read-data.d.ts +2 -2
- package/dist/netcdfjs/read-data.d.ts.map +1 -1
- package/dist/netcdfjs/read-data.js +39 -19
- package/dist/netcdfjs/read-header.d.ts +2 -2
- package/dist/netcdfjs/read-header.d.ts.map +1 -1
- package/dist/netcdfjs/read-header.js +198 -134
- package/dist/netcdfjs/read-type.d.ts +1 -1
- package/dist/netcdfjs/read-type.d.ts.map +1 -1
- package/dist/netcdfjs/read-type.js +118 -82
- package/package.json +9 -5
- package/src/netcdfjs/netcdf-reader.ts +7 -1
- package/dist/index.js.map +0 -1
- package/dist/iobuffer/iobuffer.js.map +0 -1
- package/dist/netcdf-loader.js.map +0 -1
- package/dist/netcdfjs/LICENSE +0 -24
- package/dist/netcdfjs/netcdf-reader.js.map +0 -1
- package/dist/netcdfjs/netcdf-types.js.map +0 -1
- package/dist/netcdfjs/read-data.js.map +0 -1
- package/dist/netcdfjs/read-header.js.map +0 -1
- package/dist/netcdfjs/read-type.js.map +0 -1
package/dist/netcdf-loader.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Loader, LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
|
-
import type { NetCDFHeader } from
|
|
2
|
+
import type { NetCDFHeader } from "./netcdfjs/netcdf-types.js";
|
|
3
3
|
export type NetCDF = {
|
|
4
4
|
loaderData: NetCDFHeader;
|
|
5
5
|
data: {
|
|
@@ -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,
|
|
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,mCAAgC;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;QACnB,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,mBAAmB,CAiBzE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,mBAAmB,CAI7E,CAAC"}
|
package/dist/netcdf-loader.js
CHANGED
|
@@ -1,36 +1,46 @@
|
|
|
1
1
|
import { NetCDFReader } from "./netcdfjs/netcdf-reader.js";
|
|
2
|
-
|
|
2
|
+
// __VERSION__ is injected by babel-plugin-version-inline
|
|
3
|
+
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
4
|
+
const VERSION = typeof "4.2.0-alpha.5" !== 'undefined' ? "4.2.0-alpha.5" : 'latest';
|
|
5
|
+
/**
|
|
6
|
+
* Worker loader for NETCDF
|
|
7
|
+
*/
|
|
3
8
|
export const NetCDFWorkerLoader = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
name: 'NetCDF',
|
|
10
|
+
id: 'mvt',
|
|
11
|
+
module: 'mvt',
|
|
12
|
+
version: VERSION,
|
|
13
|
+
extensions: ['cdf', 'nc'],
|
|
14
|
+
mimeTypes: [
|
|
15
|
+
'application/netcdf',
|
|
16
|
+
'application/x-netcdf'
|
|
17
|
+
// 'application/octet-stream'
|
|
18
|
+
],
|
|
19
|
+
category: 'image',
|
|
20
|
+
options: {
|
|
21
|
+
netcdf: {
|
|
22
|
+
loadVariables: false
|
|
23
|
+
}
|
|
14
24
|
}
|
|
15
|
-
}
|
|
16
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Loader for the NetCDF format
|
|
28
|
+
*/
|
|
17
29
|
export const NetCDFLoader = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
30
|
+
...NetCDFWorkerLoader,
|
|
31
|
+
parse: async (arrayBuffer, options) => parseNetCDF(arrayBuffer, options),
|
|
32
|
+
binary: true
|
|
21
33
|
};
|
|
22
34
|
function parseNetCDF(arrayBuffer, options) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
const reader = new NetCDFReader(arrayBuffer);
|
|
36
|
+
const variables = {};
|
|
37
|
+
if (options?.netcdf?.loadData) {
|
|
38
|
+
for (const variable of reader.variables) {
|
|
39
|
+
variables[variable.name] = reader.getDataVariable(variable);
|
|
40
|
+
}
|
|
29
41
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
42
|
+
return {
|
|
43
|
+
loaderData: reader.header,
|
|
44
|
+
data: variables
|
|
45
|
+
};
|
|
35
46
|
}
|
|
36
|
-
//# sourceMappingURL=netcdf-loader.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IOBuffer } from
|
|
2
|
-
import type { NetCDFHeader, NetCDFDimension, NetCDFRecordDimension, NetCDFAttribute, NetCDFVariable } from
|
|
1
|
+
import { IOBuffer } from "../iobuffer/iobuffer.js";
|
|
2
|
+
import type { NetCDFHeader, NetCDFDimension, NetCDFRecordDimension, NetCDFAttribute, NetCDFVariable } from "./netcdf-types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Reads a NetCDF v3.x file
|
|
5
5
|
* https://www.unidata.ucar.edu/software/netcdf/docs/file_format_specifications.html
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"netcdf-reader.d.ts","sourceRoot":"","sources":["../../src/netcdfjs/netcdf-reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,
|
|
1
|
+
{"version":3,"file":"netcdf-reader.d.ts","sourceRoot":"","sources":["../../src/netcdfjs/netcdf-reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,gCAA6B;AAC9C,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,cAAc,EACf,0BAAuB;AAIxB;;;;;GAKG;AACH,qBAAa,YAAY;IAChB,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,QAAQ,CAAC;gBAEZ,IAAI,KAAA;IAqBhB;;OAEG;IACH,IAAI,OAAO,8CAKV;IAED;;OAEG;IACH,IAAI,eAAe,IAAI,qBAAqB,CAE3C;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,eAAe,EAAE,CAElC;IAED;;;;;OAKG;IACH,IAAI,UAAU,IAAI,eAAe,EAAE,CAElC;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,cAAc,EAAE,CAEhC;IAED;;;;OAIG;IACH,eAAe,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO;IAK/C;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAMlD;;;;OAIG;IACH,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO;IAOjD;;;;OAIG;IACH,uBAAuB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAM5D;;;;OAIG;IACH,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,EAAE;IAiCrD,QAAQ,IAAI,MAAM;CA4BnB"}
|
|
@@ -1,103 +1,170 @@
|
|
|
1
1
|
import { IOBuffer } from "../iobuffer/iobuffer.js";
|
|
2
2
|
import { readNetCDFHeader } from "./read-header.js";
|
|
3
3
|
import { readRecord, readNonRecord } from "./read-data.js";
|
|
4
|
+
/**
|
|
5
|
+
* Reads a NetCDF v3.x file
|
|
6
|
+
* https://www.unidata.ucar.edu/software/netcdf/docs/file_format_specifications.html
|
|
7
|
+
* @param {ArrayBuffer} data - ArrayBuffer or any Typed Array (including Node.js' Buffer from v4) with the data
|
|
8
|
+
* @constructor
|
|
9
|
+
*/
|
|
4
10
|
export class NetCDFReader {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
header;
|
|
12
|
+
buffer;
|
|
13
|
+
constructor(data) {
|
|
14
|
+
const buffer = new IOBuffer(data);
|
|
15
|
+
buffer.setBigEndian();
|
|
16
|
+
// Validate that it's a NetCDF file
|
|
17
|
+
const magic = buffer.readChars(3);
|
|
18
|
+
if (magic !== 'CDF') {
|
|
19
|
+
throw new Error(`NetCDF: file should start with 'CDF', found ${magic}`);
|
|
20
|
+
}
|
|
21
|
+
// Check the NetCDF format
|
|
22
|
+
const version = buffer.readByte();
|
|
23
|
+
if (version > 2) {
|
|
24
|
+
throw new Error(`NetCDF: unsupported version ${version}`);
|
|
25
|
+
}
|
|
26
|
+
// Read the header
|
|
27
|
+
this.header = readNetCDFHeader(buffer, version);
|
|
28
|
+
this.buffer = buffer;
|
|
13
29
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
30
|
+
/**
|
|
31
|
+
* @return {string} - Version for the NetCDF format
|
|
32
|
+
*/
|
|
33
|
+
get version() {
|
|
34
|
+
if (this.header.version === 1) {
|
|
35
|
+
return 'classic format';
|
|
36
|
+
}
|
|
37
|
+
return '64-bit offset format';
|
|
17
38
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return 'classic format';
|
|
39
|
+
/**
|
|
40
|
+
* Get metadata for the record dimension
|
|
41
|
+
*/
|
|
42
|
+
get recordDimension() {
|
|
43
|
+
return this.header.recordDimension;
|
|
24
44
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
get dimensions() {
|
|
31
|
-
return this.header.dimensions;
|
|
32
|
-
}
|
|
33
|
-
get attributes() {
|
|
34
|
-
return this.header.attributes;
|
|
35
|
-
}
|
|
36
|
-
get variables() {
|
|
37
|
-
return this.header.variables;
|
|
38
|
-
}
|
|
39
|
-
attributeExists(attributeName) {
|
|
40
|
-
const attribute = this.attributes.find(val => val.name === attributeName);
|
|
41
|
-
return attribute !== undefined;
|
|
42
|
-
}
|
|
43
|
-
getAttribute(attributeName) {
|
|
44
|
-
const attribute = this.attributes.find(val => val.name === attributeName);
|
|
45
|
-
if (attribute) return attribute.value;
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
dataVariableExists(variableName) {
|
|
49
|
-
const variable = this.header.variables.find(function (val) {
|
|
50
|
-
return val.name === variableName;
|
|
51
|
-
});
|
|
52
|
-
return variable !== undefined;
|
|
53
|
-
}
|
|
54
|
-
getDataVariableAsString(variableName) {
|
|
55
|
-
const variable = this.getDataVariable(variableName);
|
|
56
|
-
if (variable) return variable.join('');
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
getDataVariable(variableName) {
|
|
60
|
-
let variable;
|
|
61
|
-
if (typeof variableName === 'string') {
|
|
62
|
-
variable = this.header.variables.find(function (val) {
|
|
63
|
-
return val.name === variableName;
|
|
64
|
-
});
|
|
65
|
-
} else {
|
|
66
|
-
variable = variableName;
|
|
45
|
+
/**
|
|
46
|
+
* Get list of dimensions (each with `name` and `size`)
|
|
47
|
+
*/
|
|
48
|
+
get dimensions() {
|
|
49
|
+
return this.header.dimensions;
|
|
67
50
|
}
|
|
68
|
-
|
|
69
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Get list of global attributes with:
|
|
53
|
+
* * `name`: String with the name of the attribute
|
|
54
|
+
* * `type`: String with the type of the attribute
|
|
55
|
+
* * `value`: A number or string with the value of the attribute
|
|
56
|
+
*/
|
|
57
|
+
get attributes() {
|
|
58
|
+
return this.header.attributes;
|
|
70
59
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Get list of variables
|
|
62
|
+
*/
|
|
63
|
+
get variables() {
|
|
64
|
+
return this.header.variables;
|
|
74
65
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Check if an attribute exists
|
|
68
|
+
* @param attributeName - Name of the attribute to find
|
|
69
|
+
* @return
|
|
70
|
+
*/
|
|
71
|
+
attributeExists(attributeName) {
|
|
72
|
+
const attribute = this.attributes.find((val) => val.name === attributeName);
|
|
73
|
+
return attribute !== undefined;
|
|
82
74
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Returns the value of an attribute
|
|
77
|
+
* @param attributeName
|
|
78
|
+
* @return Value of the attributeName or null
|
|
79
|
+
*/
|
|
80
|
+
getAttribute(attributeName) {
|
|
81
|
+
const attribute = this.attributes.find((val) => val.name === attributeName);
|
|
82
|
+
if (attribute)
|
|
83
|
+
return attribute.value;
|
|
84
|
+
return null;
|
|
87
85
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Check if a dataVariable exists
|
|
88
|
+
* @param variableName - Name of the variable to find
|
|
89
|
+
* @return
|
|
90
|
+
*/
|
|
91
|
+
dataVariableExists(variableName) {
|
|
92
|
+
const variable = this.header.variables.find(function (val) {
|
|
93
|
+
return val.name === variableName;
|
|
94
|
+
});
|
|
95
|
+
return variable !== undefined;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Returns the value of a variable as a string
|
|
99
|
+
* @param variableName
|
|
100
|
+
* @return Value of the variable as a string or null
|
|
101
|
+
*/
|
|
102
|
+
getDataVariableAsString(variableName) {
|
|
103
|
+
const variable = this.getDataVariable(variableName);
|
|
104
|
+
if (variable)
|
|
105
|
+
return variable.join('');
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Retrieves the data for a given variable
|
|
110
|
+
* @param variableName - Name of the variable to search or variable object
|
|
111
|
+
* @return List with the variable values
|
|
112
|
+
*/
|
|
113
|
+
getDataVariable(variableName) {
|
|
114
|
+
let variable;
|
|
115
|
+
if (typeof variableName === 'string') {
|
|
116
|
+
// search the variable
|
|
117
|
+
variable = this.header.variables.find(function (val) {
|
|
118
|
+
return val.name === variableName;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
variable = variableName;
|
|
123
|
+
}
|
|
124
|
+
// throws if variable not found
|
|
125
|
+
if (variable === undefined) {
|
|
126
|
+
let errorOutput;
|
|
127
|
+
if (typeof variableName === 'string') {
|
|
128
|
+
errorOutput = variableName;
|
|
129
|
+
}
|
|
130
|
+
else if (typeof variableName === 'object') {
|
|
131
|
+
errorOutput = JSON.stringify(variableName);
|
|
132
|
+
}
|
|
133
|
+
throw new Error(`NetCDF: variable not found: ${errorOutput}`);
|
|
134
|
+
}
|
|
135
|
+
// go to the offset position
|
|
136
|
+
this.buffer.seek(variable.offset);
|
|
137
|
+
if (variable.record) {
|
|
138
|
+
// record variable case
|
|
139
|
+
return readRecord(this.buffer, variable, this.header.recordDimension);
|
|
140
|
+
}
|
|
141
|
+
// non-record variable case
|
|
142
|
+
return readNonRecord(this.buffer, variable);
|
|
143
|
+
}
|
|
144
|
+
toString() {
|
|
145
|
+
const result = [];
|
|
146
|
+
result.push('DIMENSIONS');
|
|
147
|
+
for (const dimension of this.dimensions) {
|
|
148
|
+
result.push(` ${dimension.name.padEnd(30)} = size: ${dimension.size}`);
|
|
149
|
+
}
|
|
150
|
+
result.push('');
|
|
151
|
+
result.push('GLOBAL ATTRIBUTES');
|
|
152
|
+
for (const attribute of this.attributes) {
|
|
153
|
+
result.push(` ${attribute.name.padEnd(30)} = ${attribute.value}`);
|
|
154
|
+
}
|
|
155
|
+
const variables = JSON.parse(JSON.stringify(this.variables));
|
|
156
|
+
result.push('');
|
|
157
|
+
result.push('VARIABLES:');
|
|
158
|
+
for (const variable of variables) {
|
|
159
|
+
variable.value = this.getDataVariable(variable);
|
|
160
|
+
let stringify = JSON.stringify(variable.value);
|
|
161
|
+
if (stringify.length > 50)
|
|
162
|
+
stringify = stringify.substring(0, 50);
|
|
163
|
+
if (!isNaN(variable.value.length)) {
|
|
164
|
+
stringify += ` (length: ${variable.value.length})`;
|
|
165
|
+
}
|
|
166
|
+
result.push(` ${variable.name.padEnd(30)} = ${stringify}`);
|
|
167
|
+
}
|
|
168
|
+
return result.join('\n');
|
|
99
169
|
}
|
|
100
|
-
return result.join('\n');
|
|
101
|
-
}
|
|
102
170
|
}
|
|
103
|
-
//# sourceMappingURL=netcdf-reader.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IOBuffer } from
|
|
2
|
-
import type { NetCDFRecordDimension, NetCDFVariable } from
|
|
1
|
+
import type { IOBuffer } from "../iobuffer/iobuffer.js";
|
|
2
|
+
import type { NetCDFRecordDimension, NetCDFVariable } from "./netcdf-types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Read data for the given non-record variable
|
|
5
5
|
* @param buffer - Buffer for the file data
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-data.d.ts","sourceRoot":"","sources":["../../src/netcdfjs/read-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAC,
|
|
1
|
+
{"version":3,"file":"read-data.d.ts","sourceRoot":"","sources":["../../src/netcdfjs/read-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAC,gCAA6B;AACnD,OAAO,KAAK,EAAC,qBAAqB,EAAE,cAAc,EAAC,0BAAuB;AAK1E;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,QAAQ,EAChB,QAAQ,EAAE,cAAc,GACvB,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU,CAAC,EAAE,CAc7C;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,QAAQ,EAChB,QAAQ,EAAE,cAAc,EACxB,eAAe,EAAE,qBAAqB,GACrC,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU,CAAC,EAAE,CAoB7C"}
|
|
@@ -1,24 +1,44 @@
|
|
|
1
1
|
import { readType, str2num, num2bytes } from "./read-type.js";
|
|
2
|
+
// const STREAMING = 4294967295;
|
|
3
|
+
/**
|
|
4
|
+
* Read data for the given non-record variable
|
|
5
|
+
* @param buffer - Buffer for the file data
|
|
6
|
+
* @param variable - Variable metadata
|
|
7
|
+
* @return Data of the element
|
|
8
|
+
*/
|
|
2
9
|
export function readNonRecord(buffer, variable) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
// variable type
|
|
11
|
+
const type = str2num(variable.type);
|
|
12
|
+
// size of the data
|
|
13
|
+
const size = variable.size / num2bytes(type);
|
|
14
|
+
// iterates over the data
|
|
15
|
+
const data = new Array(size);
|
|
16
|
+
for (let i = 0; i < size; i++) {
|
|
17
|
+
data[i] = readType(buffer, type, 1);
|
|
18
|
+
}
|
|
19
|
+
return data;
|
|
10
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Read data for the given record variable
|
|
23
|
+
* @param buffer - Buffer for the file data
|
|
24
|
+
* @param variable - Variable metadata
|
|
25
|
+
* @param recordDimension - Record dimension metadata
|
|
26
|
+
* @return - Data of the element
|
|
27
|
+
*/
|
|
11
28
|
export function readRecord(buffer, variable, recordDimension) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
data
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
// variable type
|
|
30
|
+
const type = str2num(variable.type);
|
|
31
|
+
const width = variable.size ? variable.size / num2bytes(type) : 1;
|
|
32
|
+
// size of the data
|
|
33
|
+
// TODO streaming data
|
|
34
|
+
const size = recordDimension.length;
|
|
35
|
+
// iterates over the data
|
|
36
|
+
const data = new Array(size);
|
|
37
|
+
const step = recordDimension.recordStep;
|
|
38
|
+
for (let i = 0; i < size; i++) {
|
|
39
|
+
const currentOffset = buffer.offset;
|
|
40
|
+
data[i] = readType(buffer, type, width);
|
|
41
|
+
buffer.seek(currentOffset + step);
|
|
42
|
+
}
|
|
43
|
+
return data;
|
|
23
44
|
}
|
|
24
|
-
//# sourceMappingURL=read-data.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IOBuffer } from
|
|
2
|
-
import type { NetCDFHeader } from
|
|
1
|
+
import type { IOBuffer } from "../iobuffer/iobuffer.js";
|
|
2
|
+
import type { NetCDFHeader } from "./netcdf-types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Read the header of the file
|
|
5
5
|
* @param buffer - Buffer for the file data
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-header.d.ts","sourceRoot":"","sources":["../../src/netcdfjs/read-header.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAC,
|
|
1
|
+
{"version":3,"file":"read-header.d.ts","sourceRoot":"","sources":["../../src/netcdfjs/read-header.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAC,gCAA6B;AACnD,OAAO,KAAK,EAAC,YAAY,EAAmD,0BAAuB;AAWnG;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,CA4BhF;AA2MD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,CAWjD"}
|