Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for two dimensional variables #9

Merged
merged 1 commit into from
Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function nonRecord(buffer, variable) {
function record(buffer, variable, recordDimension) {
// variable type
const type = types.str2num(variable.type);
const width = variable.size ? variable.size / types.num2bytes(type) : 1;

// size of the data
// TODO streaming data
Expand All @@ -49,7 +50,7 @@ function record(buffer, variable, recordDimension) {

for (var i = 0; i < size; i++) {
var currentOffset = buffer.offset;
data[i] = types.readType(buffer, type, 1);
data[i] = types.readType(buffer, type, width);
buffer.seek(currentOffset + step);
}

Expand Down
Binary file added test/files/ichthyop.nc
Binary file not shown.
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ describe('Read file', function () {
reader.getDataVariable('nStaticIds')[0].should.be.equal(145);
});

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 () {
const data = fs.readFileSync(pathFiles + 'madis-sao.nc');
var reader = new NetCDFReader(data);
Expand Down