nodenetcdf 4.9.3 → 4.9.32
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/TYPESCRIPT.md +211 -0
- package/index.d.ts +389 -0
- package/package.json +7 -3
- package/scripts/test-types.js +15 -0
- package/src/Attribute.cpp +54 -0
- package/src/Attribute.h +1 -0
- package/src/Dimension.cpp +36 -0
- package/src/Dimension.h +1 -0
- package/src/File.cpp +14 -0
- package/src/File.h +1 -0
- package/src/Group.cpp +129 -14
- package/src/Group.h +1 -0
- package/src/Variable.cpp +62 -2
- package/src/Variable.h +1 -0
- package/test/attribute.js +62 -0
- package/test/json.js +174 -0
- package/test/typescript-test.ts +87 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// TypeScript test file to verify type definitions
|
|
2
|
+
import { File, Group, Variable, Dimension, Attribute, FileMode, FileFormat, NetCDFDataType } from '../index';
|
|
3
|
+
|
|
4
|
+
// Test file creation
|
|
5
|
+
const file1 = new File('test.nc', 'c!', 'nodenetcdf');
|
|
6
|
+
const file2 = new File('test2.nc', 'r');
|
|
7
|
+
|
|
8
|
+
// Test root group access
|
|
9
|
+
const root: Group = file1.root;
|
|
10
|
+
|
|
11
|
+
// Test adding dimensions
|
|
12
|
+
const timeDim: Dimension = root.addDimension('time', 0); // unlimited
|
|
13
|
+
const latDim: Dimension = root.addDimension('lat', 180);
|
|
14
|
+
const lonDim: Dimension = root.addDimension('lon', 360);
|
|
15
|
+
|
|
16
|
+
// Test dimension properties
|
|
17
|
+
const dimId: number = timeDim.id;
|
|
18
|
+
const dimLength: number = latDim.length;
|
|
19
|
+
let dimName: string = lonDim.name;
|
|
20
|
+
dimName = 'longitude'; // should be settable
|
|
21
|
+
lonDim.name = 'longitude';
|
|
22
|
+
|
|
23
|
+
// Test adding variables
|
|
24
|
+
const tempVar: Variable = root.addVariable('temperature', 'float', [timeDim, latDim, lonDim]);
|
|
25
|
+
const presVar: Variable = root.addVariable('pressure', 'double', ['time', 'lat', 'lon']);
|
|
26
|
+
|
|
27
|
+
// Test variable properties
|
|
28
|
+
const varId: number = tempVar.id;
|
|
29
|
+
const varType: NetCDFDataType = tempVar.type;
|
|
30
|
+
const varDims: Dimension[] = tempVar.dimensions;
|
|
31
|
+
const varAttrs: { [name: string]: Attribute } = tempVar.attributes;
|
|
32
|
+
|
|
33
|
+
// Test variable settings
|
|
34
|
+
tempVar.name = 'temp';
|
|
35
|
+
tempVar.endianness = 'little';
|
|
36
|
+
tempVar.checksumMode = 'fletcher32';
|
|
37
|
+
tempVar.chunkMode = 'chunked';
|
|
38
|
+
tempVar.chunkSizes = [1, 90, 180];
|
|
39
|
+
tempVar.fillMode = 'fill';
|
|
40
|
+
tempVar.fillValue = -999.0;
|
|
41
|
+
tempVar.compressionShuffle = true;
|
|
42
|
+
tempVar.compressionDeflate = true;
|
|
43
|
+
tempVar.compressionLevel = 6;
|
|
44
|
+
|
|
45
|
+
// Test reading and writing
|
|
46
|
+
const data: any = tempVar.read();
|
|
47
|
+
tempVar.write([1, 2, 3, 4, 5]);
|
|
48
|
+
|
|
49
|
+
const sliceData: any = tempVar.readSlice([0, 0, 0], [1, 10, 10]);
|
|
50
|
+
tempVar.writeSlice([0, 0, 0], [1, 10, 10], sliceData);
|
|
51
|
+
|
|
52
|
+
const stridedData: any = tempVar.readStridedSlice([0, 0, 0], [1, 90, 180], [1, 2, 2]);
|
|
53
|
+
tempVar.writeStridedSlice([0, 0, 0], [1, 90, 180], [1, 2, 2], stridedData);
|
|
54
|
+
|
|
55
|
+
// Test attributes
|
|
56
|
+
const attr1: Attribute = tempVar.addAttribute('units', 'string', 'degrees_C');
|
|
57
|
+
const attr2: Attribute = root.addAttribute('title', 'string', 'Test NetCDF File');
|
|
58
|
+
|
|
59
|
+
const attrName: string = attr1.name;
|
|
60
|
+
const attrValue: any = attr1.value;
|
|
61
|
+
attr1.name = 'unit';
|
|
62
|
+
attr1.value = 'Celsius';
|
|
63
|
+
attr1.delete();
|
|
64
|
+
|
|
65
|
+
// Test subgroups
|
|
66
|
+
const subgroup: Group = root.addSubgroup('forecast');
|
|
67
|
+
const subgroupId: number = subgroup.id;
|
|
68
|
+
const subgroupVars: { [name: string]: Variable } = subgroup.variables;
|
|
69
|
+
const subgroupDims: { [name: string]: Dimension } = subgroup.dimensions;
|
|
70
|
+
const subgroupAttrs: { [name: string]: Attribute } = subgroup.attributes;
|
|
71
|
+
const subgroupSubgroups: { [name: string]: Group } = subgroup.subgroups;
|
|
72
|
+
const subgroupName: string = subgroup.name;
|
|
73
|
+
const subgroupFullname: string = subgroup.fullname;
|
|
74
|
+
const unlimitedDim: Dimension | null = subgroup.unlimited;
|
|
75
|
+
|
|
76
|
+
// Test file operations
|
|
77
|
+
file1.sync();
|
|
78
|
+
file1.close();
|
|
79
|
+
|
|
80
|
+
// Test inspect methods
|
|
81
|
+
const fileInspect: string = file1.inspect();
|
|
82
|
+
const groupInspect: string = root.inspect();
|
|
83
|
+
const varInspect: string = tempVar.inspect();
|
|
84
|
+
const dimInspect: string = timeDim.inspect();
|
|
85
|
+
const attrInspect: string = attr2.inspect();
|
|
86
|
+
|
|
87
|
+
console.log('TypeScript type checking passed!');
|