@earthyscience/netcdf4-wasm 0.2.3 → 0.3.0

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.
@@ -3,6 +3,19 @@ import { NC_CONSTANTS, DATA_TYPE_SIZE } from './constants.js';
3
3
  const NC_MAX_NAME = 256;
4
4
  const NC_MAX_DIMS = 1024;
5
5
  const NC_MAX_VARS = 8192;
6
+ function stridedLength(count) {
7
+ return count.reduce((acc, c) => acc * c, 1);
8
+ }
9
+ // Helper: validates that the total byte allocation won't overflow a WASM32 uint32.
10
+ // Throws a RangeError if the allocation would be unsafe.
11
+ function safeByteLength(totalLength, elementSize) {
12
+ const byteLength = totalLength * elementSize;
13
+ if (byteLength > 0xFFFFFFFF) {
14
+ throw new RangeError(`Allocation size ${byteLength} exceeds WASM32 heap limit (0xFFFFFFFF). ` +
15
+ `Requested ${totalLength} elements of ${elementSize} bytes each.`);
16
+ }
17
+ return byteLength;
18
+ }
6
19
  export class WasmModuleLoader {
7
20
  static async loadModule(options = {}) {
8
21
  try {
@@ -112,6 +125,21 @@ export class WasmModuleLoader {
112
125
  const nc_get_var_uint_wrapper = module.cwrap('nc_get_var_uint_wrapper', 'number', ['number', 'number', 'number']);
113
126
  const nc_get_var_ulonglong_wrapper = module.cwrap('nc_get_var_ulonglong_wrapper', 'number', ['number', 'number', 'number']);
114
127
  const nc_get_var_string_wrapper = module.cwrap('nc_get_var_string_wrapper', 'number', ['number', 'number', 'number']);
128
+ // Stride inquiry wrappers
129
+ const nc_get_vars_schar_wrapper = module.cwrap('nc_get_vars_schar_wrapper', 'number', ['number', 'number', 'number', 'number', 'number', 'number']);
130
+ const nc_get_vars_uchar_wrapper = module.cwrap('nc_get_vars_uchar_wrapper', 'number', ['number', 'number', 'number', 'number', 'number', 'number']);
131
+ const nc_get_vars_short_wrapper = module.cwrap('nc_get_vars_short_wrapper', 'number', ['number', 'number', 'number', 'number', 'number', 'number']);
132
+ const nc_get_vars_ushort_wrapper = module.cwrap('nc_get_vars_ushort_wrapper', 'number', ['number', 'number', 'number', 'number', 'number', 'number']);
133
+ const nc_get_vars_int_wrapper = module.cwrap('nc_get_vars_int_wrapper', 'number', ['number', 'number', 'number', 'number', 'number', 'number']);
134
+ const nc_get_vars_uint_wrapper = module.cwrap('nc_get_vars_uint_wrapper', 'number', ['number', 'number', 'number', 'number', 'number', 'number']);
135
+ const nc_get_vars_float_wrapper = module.cwrap('nc_get_vars_float_wrapper', 'number', ['number', 'number', 'number', 'number', 'number', 'number']);
136
+ const nc_get_vars_double_wrapper = module.cwrap('nc_get_vars_double_wrapper', 'number', ['number', 'number', 'number', 'number', 'number', 'number']);
137
+ const nc_get_vars_longlong_wrapper = module.cwrap('nc_get_vars_longlong_wrapper', 'number', ['number', 'number', 'number', 'number', 'number', 'number']);
138
+ const nc_get_vars_ulonglong_wrapper = module.cwrap('nc_get_vars_ulonglong_wrapper', 'number', ['number', 'number', 'number', 'number', 'number', 'number']);
139
+ const nc_get_vars_string_wrapper = module.cwrap('nc_get_vars_string_wrapper', 'number', ['number', 'number', 'number', 'number', 'number', 'number']);
140
+ const nc_get_vars_wrapper = module.cwrap('nc_get_vars_wrapper', 'number', ['number', 'number', 'number', 'number', 'number', 'number']);
141
+ const nc_get_vars_text_wrapper = module.cwrap('nc_get_vars_text_wrapper', 'number', ['number', 'number', 'number', 'number', 'number', 'number']);
142
+ // const nc_get_vars_as_type_wrapper = module.cwrap('nc_get_vars_as_type_wrapper', 'number', ['number','number','number','number','number','number','number']);
115
143
  // Group inquiry wrappers
116
144
  const nc_inq_grps_wrapper = module.cwrap('nc_inq_grps_wrapper', 'number', ['number', 'number', 'number']);
117
145
  const nc_inq_grp_ncid_wrapper = module.cwrap('nc_inq_grp_ncid_wrapper', 'number', ['number', 'string', 'number']);
@@ -181,12 +209,14 @@ export class WasmModuleLoader {
181
209
  },
182
210
  nc_inq_dim: (ncid, dimid) => {
183
211
  const namePtr = module._malloc(NC_MAX_NAME + 1);
184
- const lenPtr = module._malloc(8); // size_t (use 8 bytes for safety in wasm64)
212
+ // In Emscripten wasm32 builds, size_t is 32-bit.
213
+ // (If we ever build wasm64, this will need revisiting.)
214
+ const lenPtr = module._malloc(4);
185
215
  const result = nc_inq_dim_wrapper(ncid, dimid, namePtr, lenPtr);
186
216
  let name, len;
187
217
  if (result === NC_CONSTANTS.NC_NOERR) {
188
218
  name = module.UTF8ToString(namePtr);
189
- len = module.getValue(lenPtr, 'i32'); // or 'i32' if your build uses 32-bit size_t
219
+ len = module.getValue(lenPtr, 'i32') >>> 0;
190
220
  }
191
221
  module._free(namePtr);
192
222
  module._free(lenPtr);
@@ -200,9 +230,14 @@ export class WasmModuleLoader {
200
230
  return { result, dimid };
201
231
  },
202
232
  nc_inq_dimlen: (ncid, dimid) => {
203
- const lenPtr = module._malloc(8);
233
+ // In Emscripten wasm32 builds, size_t is 32-bit.
234
+ // Allocate 4 bytes and read as unsigned i32 to avoid garbage high bits.
235
+ const lenPtr = module._malloc(4);
204
236
  const result = nc_inq_dimlen_wrapper(ncid, dimid, lenPtr);
205
- const len = result === NC_CONSTANTS.NC_NOERR ? module.getValue(lenPtr, 'i64') : undefined;
237
+ let len;
238
+ if (result === NC_CONSTANTS.NC_NOERR) {
239
+ len = module.getValue(lenPtr, 'i32') >>> 0;
240
+ }
206
241
  module._free(lenPtr);
207
242
  return { result, len };
208
243
  },
@@ -1144,6 +1179,323 @@ export class WasmModuleLoader {
1144
1179
  module._free(countPtr);
1145
1180
  return { result, data };
1146
1181
  },
1182
+ // start/count/stride → i32 / 4 bytes per element (size_t and ptrdiff_t are 4 bytes in wasm32)
1183
+ nc_get_vars_schar: (ncid, varid, start, count, stride) => {
1184
+ const totalLength = stridedLength(count);
1185
+ const dataPtr = module._malloc(safeByteLength(totalLength, 1));
1186
+ const startPtr = module._malloc(start.length * 4);
1187
+ const countPtr = module._malloc(count.length * 4);
1188
+ const stridePtr = module._malloc(stride.length * 4);
1189
+ start.forEach((v, i) => module.setValue(startPtr + i * 4, v, 'i32'));
1190
+ count.forEach((v, i) => module.setValue(countPtr + i * 4, v, 'i32'));
1191
+ stride.forEach((v, i) => module.setValue(stridePtr + i * 4, v, 'i32'));
1192
+ const result = nc_get_vars_schar_wrapper(ncid, varid, startPtr, countPtr, stridePtr, dataPtr);
1193
+ const data = result === NC_CONSTANTS.NC_NOERR
1194
+ ? new Int8Array(module.HEAP8.buffer, dataPtr, totalLength).slice()
1195
+ : undefined;
1196
+ module._free(dataPtr);
1197
+ module._free(startPtr);
1198
+ module._free(countPtr);
1199
+ module._free(stridePtr);
1200
+ return { result, data };
1201
+ },
1202
+ nc_get_vars_uchar: (ncid, varid, start, count, stride) => {
1203
+ const totalLength = stridedLength(count);
1204
+ const dataPtr = module._malloc(safeByteLength(totalLength, 1));
1205
+ const startPtr = module._malloc(start.length * 4);
1206
+ const countPtr = module._malloc(count.length * 4);
1207
+ const stridePtr = module._malloc(stride.length * 4);
1208
+ start.forEach((v, i) => module.setValue(startPtr + i * 4, v, 'i32'));
1209
+ count.forEach((v, i) => module.setValue(countPtr + i * 4, v, 'i32'));
1210
+ stride.forEach((v, i) => module.setValue(stridePtr + i * 4, v, 'i32'));
1211
+ const result = nc_get_vars_uchar_wrapper(ncid, varid, startPtr, countPtr, stridePtr, dataPtr);
1212
+ const data = result === NC_CONSTANTS.NC_NOERR
1213
+ ? new Uint8Array(module.HEAPU8.buffer, dataPtr, totalLength).slice()
1214
+ : undefined;
1215
+ module._free(dataPtr);
1216
+ module._free(startPtr);
1217
+ module._free(countPtr);
1218
+ module._free(stridePtr);
1219
+ return { result, data };
1220
+ },
1221
+ nc_get_vars_short: (ncid, varid, start, count, stride) => {
1222
+ const totalLength = stridedLength(count);
1223
+ const dataPtr = module._malloc(safeByteLength(totalLength, 2));
1224
+ const startPtr = module._malloc(start.length * 4);
1225
+ const countPtr = module._malloc(count.length * 4);
1226
+ const stridePtr = module._malloc(stride.length * 4);
1227
+ start.forEach((v, i) => module.setValue(startPtr + i * 4, v, 'i32'));
1228
+ count.forEach((v, i) => module.setValue(countPtr + i * 4, v, 'i32'));
1229
+ stride.forEach((v, i) => module.setValue(stridePtr + i * 4, v, 'i32'));
1230
+ const result = nc_get_vars_short_wrapper(ncid, varid, startPtr, countPtr, stridePtr, dataPtr);
1231
+ const data = result === NC_CONSTANTS.NC_NOERR
1232
+ ? new Int16Array(module.HEAP16.buffer, dataPtr, totalLength).slice()
1233
+ : undefined;
1234
+ module._free(dataPtr);
1235
+ module._free(startPtr);
1236
+ module._free(countPtr);
1237
+ module._free(stridePtr);
1238
+ return { result, data };
1239
+ },
1240
+ nc_get_vars_ushort: (ncid, varid, start, count, stride) => {
1241
+ const totalLength = stridedLength(count);
1242
+ const dataPtr = module._malloc(safeByteLength(totalLength, 2));
1243
+ const startPtr = module._malloc(start.length * 4);
1244
+ const countPtr = module._malloc(count.length * 4);
1245
+ const stridePtr = module._malloc(stride.length * 4);
1246
+ start.forEach((v, i) => module.setValue(startPtr + i * 4, v, 'i32'));
1247
+ count.forEach((v, i) => module.setValue(countPtr + i * 4, v, 'i32'));
1248
+ stride.forEach((v, i) => module.setValue(stridePtr + i * 4, v, 'i32'));
1249
+ const result = nc_get_vars_ushort_wrapper(ncid, varid, startPtr, countPtr, stridePtr, dataPtr);
1250
+ const data = result === NC_CONSTANTS.NC_NOERR
1251
+ ? new Uint16Array(module.HEAPU16.buffer, dataPtr, totalLength).slice()
1252
+ : undefined;
1253
+ module._free(dataPtr);
1254
+ module._free(startPtr);
1255
+ module._free(countPtr);
1256
+ module._free(stridePtr);
1257
+ return { result, data };
1258
+ },
1259
+ nc_get_vars_int: (ncid, varid, start, count, stride) => {
1260
+ const totalLength = stridedLength(count);
1261
+ const dataPtr = module._malloc(safeByteLength(totalLength, 4));
1262
+ const startPtr = module._malloc(start.length * 4);
1263
+ const countPtr = module._malloc(count.length * 4);
1264
+ const stridePtr = module._malloc(stride.length * 4);
1265
+ start.forEach((v, i) => module.setValue(startPtr + i * 4, v, 'i32'));
1266
+ count.forEach((v, i) => module.setValue(countPtr + i * 4, v, 'i32'));
1267
+ stride.forEach((v, i) => module.setValue(stridePtr + i * 4, v, 'i32'));
1268
+ const result = nc_get_vars_int_wrapper(ncid, varid, startPtr, countPtr, stridePtr, dataPtr);
1269
+ const data = result === NC_CONSTANTS.NC_NOERR
1270
+ ? new Int32Array(module.HEAP32.buffer, dataPtr, totalLength).slice()
1271
+ : undefined;
1272
+ module._free(dataPtr);
1273
+ module._free(startPtr);
1274
+ module._free(countPtr);
1275
+ module._free(stridePtr);
1276
+ return { result, data };
1277
+ },
1278
+ nc_get_vars_uint: (ncid, varid, start, count, stride) => {
1279
+ const totalLength = stridedLength(count);
1280
+ const dataPtr = module._malloc(safeByteLength(totalLength, 4));
1281
+ const startPtr = module._malloc(start.length * 4);
1282
+ const countPtr = module._malloc(count.length * 4);
1283
+ const stridePtr = module._malloc(stride.length * 4);
1284
+ start.forEach((v, i) => module.setValue(startPtr + i * 4, v, 'i32'));
1285
+ count.forEach((v, i) => module.setValue(countPtr + i * 4, v, 'i32'));
1286
+ stride.forEach((v, i) => module.setValue(stridePtr + i * 4, v, 'i32'));
1287
+ const result = nc_get_vars_uint_wrapper(ncid, varid, startPtr, countPtr, stridePtr, dataPtr);
1288
+ const data = result === NC_CONSTANTS.NC_NOERR
1289
+ ? new Uint32Array(module.HEAPU32.buffer, dataPtr, totalLength).slice()
1290
+ : undefined;
1291
+ module._free(dataPtr);
1292
+ module._free(startPtr);
1293
+ module._free(countPtr);
1294
+ module._free(stridePtr);
1295
+ return { result, data };
1296
+ },
1297
+ nc_get_vars_float: (ncid, varid, start, count, stride) => {
1298
+ const totalLength = stridedLength(count);
1299
+ const dataPtr = module._malloc(safeByteLength(totalLength, 4));
1300
+ const startPtr = module._malloc(start.length * 4);
1301
+ const countPtr = module._malloc(count.length * 4);
1302
+ const stridePtr = module._malloc(stride.length * 4);
1303
+ start.forEach((v, i) => module.setValue(startPtr + i * 4, v, 'i32'));
1304
+ count.forEach((v, i) => module.setValue(countPtr + i * 4, v, 'i32'));
1305
+ stride.forEach((v, i) => module.setValue(stridePtr + i * 4, v, 'i32'));
1306
+ const result = nc_get_vars_float_wrapper(ncid, varid, startPtr, countPtr, stridePtr, dataPtr);
1307
+ const data = result === NC_CONSTANTS.NC_NOERR
1308
+ ? new Float32Array(module.HEAPF32.buffer, dataPtr, totalLength).slice()
1309
+ : undefined;
1310
+ module._free(dataPtr);
1311
+ module._free(startPtr);
1312
+ module._free(countPtr);
1313
+ module._free(stridePtr);
1314
+ return { result, data };
1315
+ },
1316
+ nc_get_vars_double: (ncid, varid, start, count, stride) => {
1317
+ const totalLength = stridedLength(count);
1318
+ const dataPtr = module._malloc(safeByteLength(totalLength, 8));
1319
+ const startPtr = module._malloc(start.length * 4);
1320
+ const countPtr = module._malloc(count.length * 4);
1321
+ const stridePtr = module._malloc(stride.length * 4);
1322
+ start.forEach((v, i) => module.setValue(startPtr + i * 4, v, 'i32'));
1323
+ count.forEach((v, i) => module.setValue(countPtr + i * 4, v, 'i32'));
1324
+ stride.forEach((v, i) => module.setValue(stridePtr + i * 4, v, 'i32'));
1325
+ const result = nc_get_vars_double_wrapper(ncid, varid, startPtr, countPtr, stridePtr, dataPtr);
1326
+ const data = result === NC_CONSTANTS.NC_NOERR
1327
+ ? new Float64Array(module.HEAPF64.buffer, dataPtr, totalLength).slice()
1328
+ : undefined;
1329
+ module._free(dataPtr);
1330
+ module._free(startPtr);
1331
+ module._free(countPtr);
1332
+ module._free(stridePtr);
1333
+ return { result, data };
1334
+ },
1335
+ nc_get_vars_longlong: (ncid, varid, start, count, stride) => {
1336
+ const totalLength = stridedLength(count);
1337
+ const dataPtr = module._malloc(safeByteLength(totalLength, 8));
1338
+ const startPtr = module._malloc(start.length * 4);
1339
+ const countPtr = module._malloc(count.length * 4);
1340
+ const stridePtr = module._malloc(stride.length * 4);
1341
+ start.forEach((v, i) => module.setValue(startPtr + i * 4, v, 'i32'));
1342
+ count.forEach((v, i) => module.setValue(countPtr + i * 4, v, 'i32'));
1343
+ stride.forEach((v, i) => module.setValue(stridePtr + i * 4, v, 'i32'));
1344
+ const result = nc_get_vars_longlong_wrapper(ncid, varid, startPtr, countPtr, stridePtr, dataPtr);
1345
+ const data = result === NC_CONSTANTS.NC_NOERR
1346
+ ? new BigInt64Array(module.HEAP64.buffer, dataPtr, totalLength).slice()
1347
+ : undefined;
1348
+ module._free(dataPtr);
1349
+ module._free(startPtr);
1350
+ module._free(countPtr);
1351
+ module._free(stridePtr);
1352
+ return { result, data };
1353
+ },
1354
+ nc_get_vars_ulonglong: (ncid, varid, start, count, stride) => {
1355
+ const totalLength = stridedLength(count);
1356
+ const dataPtr = module._malloc(safeByteLength(totalLength, 8));
1357
+ const startPtr = module._malloc(start.length * 4);
1358
+ const countPtr = module._malloc(count.length * 4);
1359
+ const stridePtr = module._malloc(stride.length * 4);
1360
+ start.forEach((v, i) => module.setValue(startPtr + i * 4, v, 'i32'));
1361
+ count.forEach((v, i) => module.setValue(countPtr + i * 4, v, 'i32'));
1362
+ stride.forEach((v, i) => module.setValue(stridePtr + i * 4, v, 'i32'));
1363
+ const result = nc_get_vars_ulonglong_wrapper(ncid, varid, startPtr, countPtr, stridePtr, dataPtr);
1364
+ const data = result === NC_CONSTANTS.NC_NOERR
1365
+ ? new BigUint64Array(module.HEAPU64.buffer, dataPtr, totalLength).slice()
1366
+ : undefined;
1367
+ module._free(dataPtr);
1368
+ module._free(startPtr);
1369
+ module._free(countPtr);
1370
+ module._free(stridePtr);
1371
+ return { result, data };
1372
+ },
1373
+ nc_get_vars_string: (ncid, varid, start, count, stride) => {
1374
+ const totalLength = stridedLength(count);
1375
+ // validate allocation size won't overflow WASM32 uint32.
1376
+ // char* pointers are 4 bytes in wasm32, so elementSize = 4.
1377
+ const dataPtr = module._malloc(safeByteLength(totalLength, 4));
1378
+ const startPtr = module._malloc(start.length * 4);
1379
+ const countPtr = module._malloc(count.length * 4);
1380
+ const stridePtr = module._malloc(stride.length * 4);
1381
+ start.forEach((v, i) => module.setValue(startPtr + i * 4, v, 'i32'));
1382
+ count.forEach((v, i) => module.setValue(countPtr + i * 4, v, 'i32'));
1383
+ stride.forEach((v, i) => module.setValue(stridePtr + i * 4, v, 'i32'));
1384
+ const result = nc_get_vars_string_wrapper(ncid, varid, startPtr, countPtr, stridePtr, dataPtr);
1385
+ let data;
1386
+ if (result === NC_CONSTANTS.NC_NOERR) {
1387
+ data = [];
1388
+ for (let i = 0; i < totalLength; i++) {
1389
+ const strPtr = module.getValue(dataPtr + i * 4, '*');
1390
+ data.push(module.UTF8ToString(strPtr));
1391
+ }
1392
+ // free the individual strings allocated by NetCDF-C before
1393
+ // freeing the pointer array. nc_free_string_wrapper handles both.
1394
+ nc_free_string_wrapper(totalLength, dataPtr);
1395
+ }
1396
+ else {
1397
+ module._free(dataPtr);
1398
+ }
1399
+ module._free(startPtr);
1400
+ module._free(countPtr);
1401
+ module._free(stridePtr);
1402
+ return { result, data };
1403
+ },
1404
+ nc_get_vars_generic: (ncid, varid, start, count, stride, nctype) => {
1405
+ const elementSize = DATA_TYPE_SIZE[nctype];
1406
+ const totalLength = stridedLength(count);
1407
+ const startPtr = module._malloc(start.length * 4);
1408
+ const countPtr = module._malloc(count.length * 4);
1409
+ const stridePtr = module._malloc(stride.length * 4);
1410
+ start.forEach((v, i) => module.setValue(startPtr + i * 4, v, 'i32'));
1411
+ count.forEach((v, i) => module.setValue(countPtr + i * 4, v, 'i32'));
1412
+ stride.forEach((v, i) => module.setValue(stridePtr + i * 4, v, 'i32'));
1413
+ if (nctype === NC_CONSTANTS.NC_STRING) {
1414
+ // validate allocation size won't overflow WASM32 uint32.
1415
+ const dataPtr = module._malloc(safeByteLength(totalLength, 4));
1416
+ const result = nc_get_vars_string_wrapper(ncid, varid, startPtr, countPtr, stridePtr, dataPtr);
1417
+ let data;
1418
+ if (result === NC_CONSTANTS.NC_NOERR) {
1419
+ data = [];
1420
+ for (let i = 0; i < totalLength; i++) {
1421
+ const strPtr = module.getValue(dataPtr + i * 4, '*');
1422
+ data.push(module.UTF8ToString(strPtr));
1423
+ }
1424
+ // free the individual strings allocated by NetCDF-C before
1425
+ // freeing the pointer array. nc_free_string_wrapper handles both.
1426
+ nc_free_string_wrapper(totalLength, dataPtr);
1427
+ }
1428
+ else {
1429
+ module._free(dataPtr);
1430
+ }
1431
+ module._free(startPtr);
1432
+ module._free(countPtr);
1433
+ module._free(stridePtr);
1434
+ return { result, data };
1435
+ }
1436
+ // validate allocation size won't overflow WASM32 uint32.
1437
+ const dataPtr = module._malloc(safeByteLength(totalLength, elementSize));
1438
+ const result = nc_get_vars_wrapper(ncid, varid, startPtr, countPtr, stridePtr, dataPtr);
1439
+ let data;
1440
+ if (result === NC_CONSTANTS.NC_NOERR) {
1441
+ switch (nctype) {
1442
+ case NC_CONSTANTS.NC_BYTE:
1443
+ data = new Int8Array(module.HEAP8.buffer, dataPtr, totalLength).slice();
1444
+ break;
1445
+ case NC_CONSTANTS.NC_UBYTE:
1446
+ data = new Uint8Array(module.HEAPU8.buffer, dataPtr, totalLength).slice();
1447
+ break;
1448
+ case NC_CONSTANTS.NC_SHORT:
1449
+ data = new Int16Array(module.HEAP16.buffer, dataPtr, totalLength).slice();
1450
+ break;
1451
+ case NC_CONSTANTS.NC_USHORT:
1452
+ data = new Uint16Array(module.HEAPU16.buffer, dataPtr, totalLength).slice();
1453
+ break;
1454
+ case NC_CONSTANTS.NC_INT:
1455
+ data = new Int32Array(module.HEAP32.buffer, dataPtr, totalLength).slice();
1456
+ break;
1457
+ case NC_CONSTANTS.NC_UINT:
1458
+ data = new Uint32Array(module.HEAPU32.buffer, dataPtr, totalLength).slice();
1459
+ break;
1460
+ case NC_CONSTANTS.NC_FLOAT:
1461
+ data = new Float32Array(module.HEAPF32.buffer, dataPtr, totalLength).slice();
1462
+ break;
1463
+ case NC_CONSTANTS.NC_DOUBLE:
1464
+ data = new Float64Array(module.HEAPF64.buffer, dataPtr, totalLength).slice();
1465
+ break;
1466
+ case NC_CONSTANTS.NC_INT64:
1467
+ data = new BigInt64Array(module.HEAP64.buffer, dataPtr, totalLength).slice();
1468
+ break;
1469
+ case NC_CONSTANTS.NC_UINT64:
1470
+ data = new BigUint64Array(module.HEAPU64.buffer, dataPtr, totalLength).slice();
1471
+ break;
1472
+ }
1473
+ }
1474
+ module._free(dataPtr);
1475
+ module._free(startPtr);
1476
+ module._free(countPtr);
1477
+ module._free(stridePtr);
1478
+ return { result, data };
1479
+ },
1480
+ nc_get_vars_text: (ncid, varid, start, count, stride) => {
1481
+ const totalLength = stridedLength(count);
1482
+ const dataPtr = module._malloc(safeByteLength(totalLength, 1));
1483
+ const startPtr = module._malloc(start.length * 4);
1484
+ const countPtr = module._malloc(count.length * 4);
1485
+ const stridePtr = module._malloc(stride.length * 4);
1486
+ start.forEach((v, i) => module.setValue(startPtr + i * 4, v, 'i32'));
1487
+ count.forEach((v, i) => module.setValue(countPtr + i * 4, v, 'i32'));
1488
+ stride.forEach((v, i) => module.setValue(stridePtr + i * 4, v, 'i32'));
1489
+ const result = nc_get_vars_text_wrapper(ncid, varid, startPtr, countPtr, stridePtr, dataPtr);
1490
+ const data = result === NC_CONSTANTS.NC_NOERR
1491
+ ? Array.from(new TextDecoder().decode(module.HEAPU8.subarray(dataPtr, dataPtr + totalLength)), char => char === '\0' ? '' : char)
1492
+ : undefined;
1493
+ module._free(dataPtr);
1494
+ module._free(startPtr);
1495
+ module._free(countPtr);
1496
+ module._free(stridePtr);
1497
+ return { result, data };
1498
+ },
1147
1499
  };
1148
1500
  }
1149
1501
  }