Skip to content

Commit

Permalink
Release v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cheminfo-bot committed Nov 3, 2016
1 parent af856e6 commit 1e28ab5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
47 changes: 41 additions & 6 deletions dist/netcdfjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,22 @@ return /******/ (function(modules) { // webpackBootstrap

/**
* Retrieves the data for a given variable
* @param {string} variableName - Name o the variable to search
* @param {string|object} variableName - Name of the variable to search or variable object
* @return {Array}
*/
getDataVariable(variableName) {
// search the variable
var variable = this.header.variables.find(function (val) {
return val.name === variableName;
});
var variable;
if (typeof variableName === 'string') {
// search the variable
variable = this.header.variables.find(function (val) {
return val.name === variableName;
});
} else {
variable = variableName;
}

// throws if variable not found
utils.notNetcdf((variable === undefined), 'variable not found');

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

// size of the data
var size = variable.size / 4;
var size = variable.size / types.num2bytes(type);

// iterates over the data
var data = new Array(size);
Expand Down Expand Up @@ -581,6 +589,32 @@ return /******/ (function(modules) { // webpackBootstrap
}
}

/**
* Parse a number type identifier to his size in bytes
* @ignore
* @param {number} type - integer that represents the type
* @return {number} -size of the type
*/
function num2bytes(type) {
switch (Number(type)) {
case types.BYTE:
return 1;
case types.CHAR:
return 1;
case types.SHORT:
return 2;
case types.INT:
return 4;
case types.FLOAT:
return 4;
case types.DOUBLE:
return 8;
/* istanbul ignore next */
default:
return -1;
}
}

/**
* Reverse search of num2str
* @ignore
Expand Down Expand Up @@ -670,6 +704,7 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = types;
module.exports.num2str = num2str;
module.exports.num2bytes = num2bytes;
module.exports.str2num = str2num;
module.exports.readType = readType;

Expand Down
2 changes: 1 addition & 1 deletion dist/netcdfjs.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1e28ab5

Please sign in to comment.