Skip to content

Commit 1e28ab5

Browse files
committed
Release v0.3.0
1 parent af856e6 commit 1e28ab5

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

dist/netcdfjs.js

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,22 @@ return /******/ (function(modules) { // webpackBootstrap
143143

144144
/**
145145
* Retrieves the data for a given variable
146-
* @param {string} variableName - Name o the variable to search
146+
* @param {string|object} variableName - Name of the variable to search or variable object
147147
* @return {Array}
148148
*/
149149
getDataVariable(variableName) {
150-
// search the variable
151-
var variable = this.header.variables.find(function (val) {
152-
return val.name === variableName;
153-
});
150+
var variable;
151+
if (typeof variableName === 'string') {
152+
// search the variable
153+
variable = this.header.variables.find(function (val) {
154+
return val.name === variableName;
155+
});
156+
} else {
157+
variable = variableName;
158+
}
159+
160+
// throws if variable not found
161+
utils.notNetcdf((variable === undefined), 'variable not found');
154162

155163
// go to the offset position
156164
this.buffer.seek(variable.offset);
@@ -494,7 +502,7 @@ return /******/ (function(modules) { // webpackBootstrap
494502
const type = types.str2num(variable.type);
495503

496504
// size of the data
497-
var size = variable.size / 4;
505+
var size = variable.size / types.num2bytes(type);
498506

499507
// iterates over the data
500508
var data = new Array(size);
@@ -581,6 +589,32 @@ return /******/ (function(modules) { // webpackBootstrap
581589
}
582590
}
583591

592+
/**
593+
* Parse a number type identifier to his size in bytes
594+
* @ignore
595+
* @param {number} type - integer that represents the type
596+
* @return {number} -size of the type
597+
*/
598+
function num2bytes(type) {
599+
switch (Number(type)) {
600+
case types.BYTE:
601+
return 1;
602+
case types.CHAR:
603+
return 1;
604+
case types.SHORT:
605+
return 2;
606+
case types.INT:
607+
return 4;
608+
case types.FLOAT:
609+
return 4;
610+
case types.DOUBLE:
611+
return 8;
612+
/* istanbul ignore next */
613+
default:
614+
return -1;
615+
}
616+
}
617+
584618
/**
585619
* Reverse search of num2str
586620
* @ignore
@@ -670,6 +704,7 @@ return /******/ (function(modules) { // webpackBootstrap
670704

671705
module.exports = types;
672706
module.exports.num2str = num2str;
707+
module.exports.num2bytes = num2bytes;
673708
module.exports.str2num = str2num;
674709
module.exports.readType = readType;
675710

dist/netcdfjs.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)