@loaders.gl/netcdf 4.0.0-alpha.4 → 4.0.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/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.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -3
- package/dist/iobuffer/iobuffer.d.ts +254 -0
- package/dist/iobuffer/iobuffer.d.ts.map +1 -0
- package/dist/iobuffer/iobuffer.js +425 -370
- package/dist/netcdf-loader.d.ts +52 -0
- package/dist/netcdf-loader.d.ts.map +1 -0
- package/dist/netcdf-loader.js +46 -36
- package/dist/netcdfjs/netcdf-reader.d.ts +68 -0
- package/dist/netcdfjs/netcdf-reader.d.ts.map +1 -0
- package/dist/netcdfjs/netcdf-reader.js +155 -126
- package/dist/netcdfjs/netcdf-types.d.ts +70 -0
- package/dist/netcdfjs/netcdf-types.d.ts.map +1 -0
- package/dist/netcdfjs/netcdf-types.js +2 -2
- package/dist/netcdfjs/read-data.d.ts +18 -0
- package/dist/netcdfjs/read-data.d.ts.map +1 -0
- package/dist/netcdfjs/read-data.js +47 -26
- package/dist/netcdfjs/read-header.d.ts +16 -0
- package/dist/netcdfjs/read-header.d.ts.map +1 -0
- package/dist/netcdfjs/read-header.js +206 -173
- package/dist/netcdfjs/read-type.d.ts +36 -0
- package/dist/netcdfjs/read-type.d.ts.map +1 -0
- package/dist/netcdfjs/read-type.js +130 -117
- package/package.json +7 -7
- 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
|
@@ -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;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IOBuffer } from '../iobuffer/iobuffer';
|
|
2
|
+
import type { NetCDFHeader } from './netcdf-types';
|
|
3
|
+
/**
|
|
4
|
+
* Read the header of the file
|
|
5
|
+
* @param buffer - Buffer for the file data
|
|
6
|
+
* @param version - Version of the file
|
|
7
|
+
* @return - Header
|
|
8
|
+
*/
|
|
9
|
+
export declare function readNetCDFHeader(buffer: IOBuffer, version: number): NetCDFHeader;
|
|
10
|
+
/**
|
|
11
|
+
* Reads the name
|
|
12
|
+
* @param buffer - Buffer for the file data
|
|
13
|
+
* @return Name
|
|
14
|
+
*/
|
|
15
|
+
export declare function readName(buffer: IOBuffer): string;
|
|
16
|
+
//# sourceMappingURL=read-header.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-header.d.ts","sourceRoot":"","sources":["../../src/netcdfjs/read-header.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,EAAC,YAAY,EAAmD,MAAM,gBAAgB,CAAC;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"}
|
|
@@ -1,197 +1,230 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readName = exports.readNetCDFHeader = void 0;
|
|
4
|
+
const read_type_1 = require("./read-type");
|
|
5
|
+
// Grammar constants
|
|
2
6
|
const ZERO = 0;
|
|
3
7
|
const NC_DIMENSION = 10;
|
|
4
8
|
const NC_VARIABLE = 11;
|
|
5
9
|
const NC_ATTRIBUTE = 12;
|
|
6
10
|
const NC_UNLIMITED = 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Read the header of the file
|
|
13
|
+
* @param buffer - Buffer for the file data
|
|
14
|
+
* @param version - Version of the file
|
|
15
|
+
* @return - Header
|
|
16
|
+
*/
|
|
17
|
+
function readNetCDFHeader(buffer, version) {
|
|
18
|
+
// Length of record dimension
|
|
19
|
+
// sum of the varSize's of all the record variables.
|
|
20
|
+
const recordDimensionLength = buffer.readUint32();
|
|
21
|
+
// List of dimensions
|
|
22
|
+
const dimList = readDimensionsList(buffer);
|
|
23
|
+
// List of global attributes
|
|
24
|
+
const attributes = readAttributesList(buffer);
|
|
25
|
+
// List of variables
|
|
26
|
+
const variableList = readVariablesList(buffer, dimList.recordId, version);
|
|
27
|
+
const header = {
|
|
28
|
+
version,
|
|
29
|
+
recordDimension: {
|
|
30
|
+
length: recordDimensionLength,
|
|
31
|
+
id: dimList.recordId,
|
|
32
|
+
name: dimList.recordName,
|
|
33
|
+
recordStep: variableList.recordStep
|
|
34
|
+
},
|
|
35
|
+
dimensions: dimList.dimensions,
|
|
36
|
+
variables: variableList.variables,
|
|
37
|
+
attributes
|
|
38
|
+
};
|
|
39
|
+
return header;
|
|
25
40
|
}
|
|
26
|
-
|
|
41
|
+
exports.readNetCDFHeader = readNetCDFHeader;
|
|
42
|
+
/**
|
|
43
|
+
* Read list of dimensions
|
|
44
|
+
* @ignore
|
|
45
|
+
* @param {IOBuffer} buffer - Buffer for the file data
|
|
46
|
+
*/
|
|
27
47
|
function readDimensionsList(buffer) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
48
|
+
const dimList = buffer.readUint32();
|
|
49
|
+
if (dimList === ZERO) {
|
|
50
|
+
if (buffer.readUint32() !== ZERO) {
|
|
51
|
+
throw new Error('NetCDF: wrong empty tag for list of dimensions');
|
|
52
|
+
}
|
|
53
|
+
// TODO - is this empty dimension list supported / recoverable?
|
|
54
|
+
return {
|
|
55
|
+
recordId: 0,
|
|
56
|
+
recordName: '',
|
|
57
|
+
dimensions: []
|
|
58
|
+
};
|
|
33
59
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
recordId = dim;
|
|
57
|
-
recordName = name;
|
|
60
|
+
if (dimList !== NC_DIMENSION) {
|
|
61
|
+
throw new Error('NetCDF: wrong tag for list of dimensions');
|
|
62
|
+
}
|
|
63
|
+
// Length of dimensions
|
|
64
|
+
const dimensionSize = buffer.readUint32();
|
|
65
|
+
const dimensions = new Array(dimensionSize);
|
|
66
|
+
let recordId;
|
|
67
|
+
let recordName;
|
|
68
|
+
for (let dim = 0; dim < dimensionSize; dim++) {
|
|
69
|
+
// Read name
|
|
70
|
+
const name = readName(buffer);
|
|
71
|
+
// Read dimension size
|
|
72
|
+
const size = buffer.readUint32();
|
|
73
|
+
if (size === NC_UNLIMITED) {
|
|
74
|
+
// in netcdf 3 one field can be of size unlimmited
|
|
75
|
+
recordId = dim;
|
|
76
|
+
recordName = name;
|
|
77
|
+
}
|
|
78
|
+
dimensions[dim] = {
|
|
79
|
+
name,
|
|
80
|
+
size
|
|
81
|
+
};
|
|
58
82
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
83
|
+
return {
|
|
84
|
+
dimensions,
|
|
85
|
+
recordId,
|
|
86
|
+
recordName
|
|
63
87
|
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
dimensions,
|
|
68
|
-
recordId,
|
|
69
|
-
recordName
|
|
70
|
-
};
|
|
71
88
|
}
|
|
72
|
-
|
|
89
|
+
/**
|
|
90
|
+
* List of attributes
|
|
91
|
+
* @ignore
|
|
92
|
+
* @param buffer - Buffer for the file data
|
|
93
|
+
* @return List of attributes with:
|
|
94
|
+
*/
|
|
73
95
|
function readAttributesList(buffer) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
96
|
+
const gAttList = buffer.readUint32();
|
|
97
|
+
if (gAttList === ZERO) {
|
|
98
|
+
if (buffer.readUint32() !== ZERO) {
|
|
99
|
+
throw new Error('NetCDF: wrong empty tag for list of attributes');
|
|
100
|
+
}
|
|
101
|
+
return [];
|
|
79
102
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (gAttList !== NC_ATTRIBUTE) {
|
|
85
|
-
throw new Error('NetCDF: wrong tag for list of attributes');
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const attributeSize = buffer.readUint32();
|
|
89
|
-
const attributes = new Array(attributeSize);
|
|
90
|
-
|
|
91
|
-
for (let gAtt = 0; gAtt < attributeSize; gAtt++) {
|
|
92
|
-
const name = readName(buffer);
|
|
93
|
-
const type = buffer.readUint32();
|
|
94
|
-
|
|
95
|
-
if (type < 1 || type > 6) {
|
|
96
|
-
throw new Error("NetCDF: non valid type ".concat(type));
|
|
103
|
+
if (gAttList !== NC_ATTRIBUTE) {
|
|
104
|
+
throw new Error('NetCDF: wrong tag for list of attributes');
|
|
97
105
|
}
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
// Length of attributes
|
|
107
|
+
const attributeSize = buffer.readUint32();
|
|
108
|
+
const attributes = new Array(attributeSize);
|
|
109
|
+
for (let gAtt = 0; gAtt < attributeSize; gAtt++) {
|
|
110
|
+
// Read name
|
|
111
|
+
const name = readName(buffer);
|
|
112
|
+
// Read type
|
|
113
|
+
const type = buffer.readUint32();
|
|
114
|
+
if (type < 1 || type > 6) {
|
|
115
|
+
throw new Error(`NetCDF: non valid type ${type}`);
|
|
116
|
+
}
|
|
117
|
+
// Read attribute
|
|
118
|
+
const size = buffer.readUint32();
|
|
119
|
+
const value = (0, read_type_1.readType)(buffer, type, size);
|
|
120
|
+
// Apply padding
|
|
121
|
+
padding(buffer);
|
|
122
|
+
attributes[gAtt] = {
|
|
123
|
+
name,
|
|
124
|
+
type: (0, read_type_1.num2str)(type),
|
|
125
|
+
value
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
return attributes;
|
|
110
129
|
}
|
|
111
|
-
|
|
130
|
+
/**
|
|
131
|
+
* List of variables
|
|
132
|
+
* @param buffer - Buffer for the file data
|
|
133
|
+
* @param recordId - Id of the unlimited dimension (also called record dimension)
|
|
134
|
+
* This value may be undefined if there is no unlimited dimension
|
|
135
|
+
* @param {number} version - Version of the file
|
|
136
|
+
*/
|
|
137
|
+
// eslint-disable-next-line max-statements, complexity
|
|
112
138
|
function readVariablesList(buffer, recordId, version) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
139
|
+
const varList = buffer.readUint32();
|
|
140
|
+
let recordStep = 0;
|
|
141
|
+
if (varList === ZERO) {
|
|
142
|
+
if (buffer.readUint32() !== ZERO) {
|
|
143
|
+
throw new Error('NetCDF: wrong empty tag for list of variables');
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
recordStep,
|
|
147
|
+
variables: []
|
|
148
|
+
};
|
|
119
149
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
recordStep,
|
|
123
|
-
variables: []
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (varList !== NC_VARIABLE) {
|
|
128
|
-
throw new Error('NetCDF: wrong tag for list of variables');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const variableSize = buffer.readUint32();
|
|
132
|
-
const variables = new Array(variableSize);
|
|
133
|
-
|
|
134
|
-
for (let v = 0; v < variableSize; v++) {
|
|
135
|
-
const name = readName(buffer);
|
|
136
|
-
const dimensionality = buffer.readUint32();
|
|
137
|
-
const dimensionsIds = new Array(dimensionality);
|
|
138
|
-
|
|
139
|
-
for (let dim = 0; dim < dimensionality; dim++) {
|
|
140
|
-
dimensionsIds[dim] = buffer.readUint32();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const attributes = readAttributesList(buffer);
|
|
144
|
-
const type = buffer.readUint32();
|
|
145
|
-
|
|
146
|
-
if (type < 1 && type > 6) {
|
|
147
|
-
throw new Error("NetCDF: non valid type ".concat(type));
|
|
150
|
+
if (varList !== NC_VARIABLE) {
|
|
151
|
+
throw new Error('NetCDF: wrong tag for list of variables');
|
|
148
152
|
}
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
153
|
+
// Length of variables
|
|
154
|
+
const variableSize = buffer.readUint32();
|
|
155
|
+
const variables = new Array(variableSize);
|
|
156
|
+
for (let v = 0; v < variableSize; v++) {
|
|
157
|
+
// Read name
|
|
158
|
+
const name = readName(buffer);
|
|
159
|
+
// Read dimensionality of the variable
|
|
160
|
+
const dimensionality = buffer.readUint32();
|
|
161
|
+
// Index into the list of dimensions
|
|
162
|
+
const dimensionsIds = new Array(dimensionality);
|
|
163
|
+
for (let dim = 0; dim < dimensionality; dim++) {
|
|
164
|
+
dimensionsIds[dim] = buffer.readUint32();
|
|
165
|
+
}
|
|
166
|
+
// Read variables size
|
|
167
|
+
const attributes = readAttributesList(buffer);
|
|
168
|
+
// Read type
|
|
169
|
+
const type = buffer.readUint32();
|
|
170
|
+
if (type < 1 && type > 6) {
|
|
171
|
+
throw new Error(`NetCDF: non valid type ${type}`);
|
|
172
|
+
}
|
|
173
|
+
// Read variable size
|
|
174
|
+
// The 32-bit varSize field is not large enough to contain the size of variables that require
|
|
175
|
+
// more than 2^32 - 4 bytes, so 2^32 - 1 is used in the varSize field for such variables.
|
|
176
|
+
const varSize = buffer.readUint32();
|
|
177
|
+
// Read offset
|
|
178
|
+
let offset = buffer.readUint32();
|
|
179
|
+
if (version === 2) {
|
|
180
|
+
if (offset > 0) {
|
|
181
|
+
throw new Error('NetCDF: offsets larger than 4GB not supported');
|
|
182
|
+
}
|
|
183
|
+
offset = buffer.readUint32();
|
|
184
|
+
}
|
|
185
|
+
let record = false;
|
|
186
|
+
// Count amount of record variables
|
|
187
|
+
if (typeof recordId !== 'undefined' && dimensionsIds[0] === recordId) {
|
|
188
|
+
recordStep += varSize;
|
|
189
|
+
record = true;
|
|
190
|
+
}
|
|
191
|
+
variables[v] = {
|
|
192
|
+
name,
|
|
193
|
+
dimensions: dimensionsIds,
|
|
194
|
+
attributes,
|
|
195
|
+
type: (0, read_type_1.num2str)(type),
|
|
196
|
+
size: varSize,
|
|
197
|
+
offset,
|
|
198
|
+
record
|
|
199
|
+
};
|
|
159
200
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (typeof recordId !== 'undefined' && dimensionsIds[0] === recordId) {
|
|
164
|
-
recordStep += varSize;
|
|
165
|
-
record = true;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
variables[v] = {
|
|
169
|
-
name,
|
|
170
|
-
dimensions: dimensionsIds,
|
|
171
|
-
attributes,
|
|
172
|
-
type: num2str(type),
|
|
173
|
-
size: varSize,
|
|
174
|
-
offset,
|
|
175
|
-
record
|
|
201
|
+
return {
|
|
202
|
+
variables,
|
|
203
|
+
recordStep
|
|
176
204
|
};
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return {
|
|
180
|
-
variables,
|
|
181
|
-
recordStep
|
|
182
|
-
};
|
|
183
205
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
206
|
+
// HELPERS
|
|
207
|
+
/**
|
|
208
|
+
* Reads the name
|
|
209
|
+
* @param buffer - Buffer for the file data
|
|
210
|
+
* @return Name
|
|
211
|
+
*/
|
|
212
|
+
function readName(buffer) {
|
|
213
|
+
// Read name
|
|
214
|
+
const nameLength = buffer.readUint32();
|
|
215
|
+
const name = buffer.readChars(nameLength);
|
|
216
|
+
// validate name
|
|
217
|
+
// TODO
|
|
218
|
+
// Apply padding
|
|
219
|
+
padding(buffer);
|
|
220
|
+
return name;
|
|
190
221
|
}
|
|
191
|
-
|
|
222
|
+
exports.readName = readName;
|
|
223
|
+
/**
|
|
224
|
+
* Moves 1, 2, or 3 bytes to next 4-byte boundary
|
|
225
|
+
*/
|
|
192
226
|
function padding(buffer) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
227
|
+
if (buffer.offset % 4 !== 0) {
|
|
228
|
+
buffer.skip(4 - (buffer.offset % 4));
|
|
229
|
+
}
|
|
196
230
|
}
|
|
197
|
-
//# sourceMappingURL=read-header.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { IOBuffer } from '../iobuffer/iobuffer';
|
|
2
|
+
export declare const TYPES: {
|
|
3
|
+
BYTE: number;
|
|
4
|
+
CHAR: number;
|
|
5
|
+
SHORT: number;
|
|
6
|
+
INT: number;
|
|
7
|
+
FLOAT: number;
|
|
8
|
+
DOUBLE: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Given a type and a size reads the next element
|
|
12
|
+
* @param buffer - Buffer for the file data
|
|
13
|
+
* @param type - Type of the data to read
|
|
14
|
+
* @param size - Size of the element to read
|
|
15
|
+
* @return
|
|
16
|
+
*/
|
|
17
|
+
export declare function readType(buffer: IOBuffer, type: number, size: number): string | number | number[] | Uint8Array;
|
|
18
|
+
/**
|
|
19
|
+
* Parse a number into their respective type
|
|
20
|
+
* @param type - integer that represents the type
|
|
21
|
+
* @return parsed value of the type
|
|
22
|
+
*/
|
|
23
|
+
export declare function num2str(type: number): string;
|
|
24
|
+
/**
|
|
25
|
+
* Parse a number type identifier to his size in bytes
|
|
26
|
+
* @param type - integer that represents the type
|
|
27
|
+
* @return size of the type
|
|
28
|
+
*/
|
|
29
|
+
export declare function num2bytes(type: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* Reverse search of num2str
|
|
32
|
+
* @param type string that represents the type
|
|
33
|
+
* @return parsed value of the type
|
|
34
|
+
*/
|
|
35
|
+
export declare function str2num(type: string): number;
|
|
36
|
+
//# sourceMappingURL=read-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-type.d.ts","sourceRoot":"","sources":["../../src/netcdfjs/read-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAE9C,eAAO,MAAM,KAAK;;;;;;;CAOjB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,QAAQ,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU,CAkBzC;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAkB5C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAkB9C;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAkB5C"}
|