@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.
- package/dist/es5/index.js +20 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/iobuffer/iobuffer.js +369 -0
- package/dist/es5/iobuffer/iobuffer.js.map +1 -0
- package/dist/es5/netcdf-loader.js +81 -0
- package/dist/es5/netcdf-loader.js.map +1 -0
- package/dist/es5/netcdfjs/netcdf-reader.js +173 -0
- package/dist/es5/netcdfjs/netcdf-reader.js.map +1 -0
- package/dist/es5/netcdfjs/netcdf-types.js +2 -0
- package/dist/es5/netcdfjs/netcdf-types.js.map +1 -0
- package/dist/es5/netcdfjs/read-data.js +31 -0
- package/dist/es5/netcdfjs/read-data.js.map +1 -0
- package/dist/es5/netcdfjs/read-header.js +168 -0
- package/dist/es5/netcdfjs/read-header.js.map +1 -0
- package/dist/es5/netcdfjs/read-type.js +108 -0
- package/dist/es5/netcdfjs/read-type.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/iobuffer/iobuffer.js +270 -0
- package/dist/esm/iobuffer/iobuffer.js.map +1 -0
- package/dist/esm/netcdf-loader.js +38 -0
- package/dist/esm/netcdf-loader.js.map +1 -0
- package/dist/esm/netcdfjs/LICENSE +24 -0
- package/dist/esm/netcdfjs/netcdf-reader.js +104 -0
- package/dist/esm/netcdfjs/netcdf-reader.js.map +1 -0
- package/dist/esm/netcdfjs/netcdf-types.js +2 -0
- package/dist/esm/netcdfjs/netcdf-types.js.map +1 -0
- package/dist/esm/netcdfjs/read-data.js +24 -0
- package/dist/esm/netcdfjs/read-data.js.map +1 -0
- package/dist/esm/netcdfjs/read-header.js +161 -0
- package/dist/esm/netcdfjs/read-header.js.map +1 -0
- package/dist/esm/netcdfjs/read-type.js +97 -0
- package/dist/esm/netcdfjs/read-type.js.map +1 -0
- package/dist/index.js +7 -3
- package/dist/iobuffer/iobuffer.d.ts +1 -1
- package/dist/iobuffer/iobuffer.d.ts.map +1 -1
- package/dist/iobuffer/iobuffer.js +425 -370
- package/dist/netcdf-loader.d.ts +2 -2
- package/dist/netcdf-loader.d.ts.map +1 -1
- package/dist/netcdf-loader.js +46 -36
- package/dist/netcdfjs/netcdf-reader.js +155 -126
- package/dist/netcdfjs/netcdf-types.d.ts +5 -5
- package/dist/netcdfjs/netcdf-types.d.ts.map +1 -1
- package/dist/netcdfjs/netcdf-types.js +2 -2
- package/dist/netcdfjs/read-data.js +47 -26
- package/dist/netcdfjs/read-header.js +206 -173
- package/dist/netcdfjs/read-type.js +130 -117
- package/package.json +5 -5
- 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/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/{netcdfjs → es5/netcdfjs}/LICENSE +0 -0
package/dist/netcdf-loader.d.ts
CHANGED
|
@@ -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
|
|
3
|
+
export type NetCDF = {
|
|
4
4
|
loaderData: NetCDFHeader;
|
|
5
5
|
data: {
|
|
6
6
|
[variableName: string]: any[][];
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
-
export
|
|
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,
|
|
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"}
|
package/dist/netcdf-loader.js
CHANGED
|
@@ -1,42 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
data: variables
|
|
37
|
-
};
|
|
45
|
+
return {
|
|
46
|
+
loaderData: reader.header,
|
|
47
|
+
data: variables
|
|
48
|
+
};
|
|
38
49
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
//# sourceMappingURL=netcdf-loader.js.map
|
|
50
|
+
// Type tests
|
|
51
|
+
exports._typecheckNetCDFWorkerLoader = exports.NetCDFWorkerLoader;
|
|
52
|
+
exports._typecheckNetCDFLoader = exports.NetCDFLoader;
|
|
@@ -1,136 +1,165 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
26
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
89
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Get list of variables
|
|
63
|
+
*/
|
|
64
|
+
get variables() {
|
|
65
|
+
return this.header.variables;
|
|
96
66
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
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
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,28 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
49
|
+
exports.readRecord = readRecord;
|