Comparing version 0.3.0 to 0.3.1
{ | ||
"name": "netcdfjs", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Read and explore NetCDF files", | ||
@@ -23,20 +23,21 @@ "keywords": [ | ||
"test": "npm run test-mocha && npm run eslint", | ||
"test-mocha": "mocha --require should --reporter mocha-better-spec-reporter --recursive", | ||
"test-cov": "istanbul cover node_modules/.bin/_mocha -- --require should --reporter dot --recursive", | ||
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- --require should --reporter dot --recursive", | ||
"test-cov": "istanbul cover node_modules/.bin/_mocha -- --require should --reporter dot --recursive && codecov", | ||
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- --require should --reporter dot --recursive && codecov", | ||
"test-mocha": "mocha --require should --reporter mocha-better-spec-reporter", | ||
"build": "cheminfo build" | ||
}, | ||
"devDependencies": { | ||
"cheminfo-tools": "^1.5.0", | ||
"eslint": "^3.4.0", | ||
"eslint-config-cheminfo": "^1.2.0", | ||
"cheminfo-tools": "^1.15.0", | ||
"codecov": "^2.1.0", | ||
"eslint": "^3.18.0", | ||
"eslint-config-cheminfo": "^1.7.0", | ||
"eslint-plugin-no-only-tests": "^1.1.0", | ||
"istanbul": "^0.4.4", | ||
"mocha": "^3.1.2", | ||
"mocha-better-spec-reporter": "^3.0.2", | ||
"should": "^11.1.1" | ||
"istanbul": "^0.4.5", | ||
"mocha": "^3.2.0", | ||
"mocha-better-spec-reporter": "^3.1.0", | ||
"should": "^11.2.1" | ||
}, | ||
"dependencies": { | ||
"iobuffer": "^2.1.0" | ||
"iobuffer": "^3.2.0" | ||
} | ||
} |
117
README.md
@@ -19,3 +19,3 @@ # netcdfjs | ||
## Example | ||
### Example I: NodeJS | ||
@@ -33,2 +33,117 @@ ```js | ||
### Example II: Load from URL (does not require node) | ||
```js | ||
// First load the netcdfjs library as normal : <script src='./dist/netcdfjs.js'></script> | ||
// You could use the oficial CDN: <script src='http://www.lactame.com/lib/netcdfjs/0.3.0/netcdfjs.min.js'></script> | ||
var urlpath = "http://www.unidata.ucar.edu/software/netcdf/examples/madis-sao.nc" | ||
var reader; | ||
var oReq = new XMLHttpRequest(); | ||
oReq.open("GET", urlpath, true); | ||
oReq.responseType = "blob"; | ||
oReq.onload = function(oEvent) { | ||
var blob = oReq.response; | ||
reader_url = new FileReader(); | ||
reader_url.onload = function(e) { | ||
reader = new netcdfjs(this.result); | ||
} | ||
reader_url.readAsArrayBuffer(blob); | ||
}; | ||
oReq.send(); //start process | ||
reader.getDataVariable('wmoId'); // go to offset and read it | ||
``` | ||
### Example III: Client side file upload. | ||
This example creates a file input element and allows the user to select a file from their personal machine. | ||
```js | ||
var reader; | ||
var progress = document.querySelector('.percent'); | ||
function abortRead() { reader.abort(); } | ||
function handleFileSelect(evt) { | ||
// Reset progress indicator on new file selection. | ||
progress.style.width = '0%'; | ||
progress.textContent = '0%'; | ||
reader = new FileReader(); | ||
reader.onerror = errorHandler; | ||
reader.onprogress = updateProgress; | ||
reader.onabort = function(e) { | ||
alert('File read cancelled'); | ||
}; | ||
reader.onloadstart = function(e) { | ||
document.getElementById('progress_bar').className = 'loading'; | ||
}; | ||
reader.onload = function(e) { | ||
// Ensure that the progress bar displays 100% at the end. | ||
progress.style.width = '100%'; | ||
progress.textContent = '100%'; | ||
setTimeout("document.getElementById('progress_bar').className='';", 2000); | ||
//var reader = new NetCDFReader(reader.result); | ||
//replace reader with NetCDF reader | ||
reader = new netcdfjs(this.result); | ||
reader.getDataVariable('wmoId'); // go to offset and read it | ||
//... your program here ..// | ||
} | ||
reader.readAsArrayBuffer(evt.target.files[0]); | ||
} | ||
// Make input element <input type="file" id="files" name="file" /> | ||
var input = document.createElement("input"); | ||
input.id='files' | ||
input.type = "file"; | ||
input.className = "file"; | ||
document.body.appendChild(input); // put it into the DOM | ||
// Make a Progress bar <div id="progress_bar"><div class="percent">0%</div></div> | ||
var progress = document.createElement("div"); | ||
progress.id='progress_bar'; | ||
inner = document.createElement("div"); | ||
inner.className = "percent"; | ||
inner.id='innerdiv' // set the CSS class | ||
progress.appendChild(inner); | ||
document.body.appendChild(progress); // put it into the DOM | ||
//Start event listener to check if a file has been selected | ||
run = document.getElementById('files').addEventListener('change', handleFileSelect, false); | ||
///Progress bar and other functions | ||
function errorHandler(evt) { | ||
switch(evt.target.error.code) { | ||
case evt.target.error.NOT_FOUND_ERR: | ||
alert('File Not Found!'); break; | ||
case evt.target.error.NOT_READABLE_ERR: | ||
alert('File is not readable');break; | ||
case evt.target.error.ABORT_ERR: break; | ||
default: alert('An error occurred reading this file.'); | ||
}; | ||
} | ||
function updateProgress(evt) { | ||
// evt is an ProgressEvent. Updates progress bar | ||
if (evt.lengthComputable) { | ||
var percentLoaded = Math.round((evt.loaded / evt.total) * 100); | ||
// Increase the progress bar length. | ||
if (percentLoaded < 100) { | ||
progress.style.width = percentLoaded + '%'; | ||
progress.textContent = percentLoaded + '%'; | ||
} | ||
} | ||
} | ||
``` | ||
## License | ||
@@ -35,0 +150,0 @@ |
@@ -41,2 +41,3 @@ 'use strict'; | ||
const type = types.str2num(variable.type); | ||
const width = variable.size ? variable.size / types.num2bytes(type) : 1; | ||
@@ -53,3 +54,3 @@ // size of the data | ||
var currentOffset = buffer.offset; | ||
data[i] = types.readType(buffer, type, 1); | ||
data[i] = types.readType(buffer, type, width); | ||
buffer.seek(currentOffset + step); | ||
@@ -56,0 +57,0 @@ } |
@@ -91,3 +91,3 @@ 'use strict'; | ||
* @param {string|object} variableName - Name of the variable to search or variable object | ||
* @return {Array} | ||
* @return {Array} - List with the variable values | ||
*/ | ||
@@ -94,0 +94,0 @@ getDataVariable(variableName) { |
@@ -100,2 +100,12 @@ 'use strict'; | ||
it('read 2 dimensional variable', function () { | ||
const data = fs.readFileSync(pathFiles + 'ichthyop.nc'); | ||
var reader = new NetCDFReader(data); | ||
reader.getDataVariable('time').should.have.length(49); | ||
reader.getDataVariable('time')[0].should.be.equal(1547070300); | ||
reader.getDataVariable('lat').should.have.length(49); | ||
reader.getDataVariable('lat')[0].should.have.length(1000); | ||
reader.getDataVariable('lat')[0][0].should.be.equal(53.26256561279297); | ||
}); | ||
it('read record variable with string', function () { | ||
@@ -102,0 +112,0 @@ const data = fs.readFileSync(pathFiles + 'madis-sao.nc'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
5434567
45
2411
161
9
17
+ Addediobuffer@3.2.0(transitive)
+ Addedutf8@2.1.2(transitive)
- Removediobuffer@2.1.0(transitive)
Updatediobuffer@^3.2.0