@@ -143,14 +143,22 @@ return /******/ (function(modules) { // webpackBootstrap
143
143
144
144
/**
145
145
* 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
147
147
* @return {Array }
148
148
*/
149
149
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' ) ;
154
162
155
163
// go to the offset position
156
164
this . buffer . seek ( variable . offset ) ;
@@ -494,7 +502,7 @@ return /******/ (function(modules) { // webpackBootstrap
494
502
const type = types . str2num ( variable . type ) ;
495
503
496
504
// size of the data
497
- var size = variable . size / 4 ;
505
+ var size = variable . size / types . num2bytes ( type ) ;
498
506
499
507
// iterates over the data
500
508
var data = new Array ( size ) ;
@@ -581,6 +589,32 @@ return /******/ (function(modules) { // webpackBootstrap
581
589
}
582
590
}
583
591
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
+
584
618
/**
585
619
* Reverse search of num2str
586
620
* @ignore
@@ -670,6 +704,7 @@ return /******/ (function(modules) { // webpackBootstrap
670
704
671
705
module . exports = types ;
672
706
module . exports . num2str = num2str ;
707
+ module . exports . num2bytes = num2bytes ;
673
708
module . exports . str2num = str2num ;
674
709
module . exports . readType = readType ;
675
710
0 commit comments