Skip to content

start implementing data representation parsing #4

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
34 changes: 34 additions & 0 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ var sectionParsers = {

return rv;
},
5: function(binary) {
var rv = {};
rv.dataPointCount = binary.read('uint32');
rv.templateNumber = binary.read('uint16');

// Parse representation
var dataReprParser = dataRepresentationParsers[rv.templateNumber];
if(!dataReprParser) {
// console.warn('Unknown data representation template: ' + rv.templateNumber);
return rv;
}
rv.representation = dataReprParser(binary);
return rv;
},
};

// Parser for scale factor / scaled value. See 92.1.12
Expand Down Expand Up @@ -319,3 +333,23 @@ var gridParsers = {
return rv;
},
};

var dataRepresentationParsers = {
// Grid point data - simple packing
0: function(binary) {
var rv = {};
rv.name = 'Grid point data - simple packing';
rv.referenceValue = binary.read('float32');
rv.binaryScale = binary.read('uint16');
rv.decimalScale = binary.read('uint16');
rv.bitCount = binary.read('uint8');
rv.dataType = tables.lookup(tables.tables.OriginalFieldType, binary.read('uint8'));
return rv;
},
// Grid point data - complex packing and spatial differencing
3: function(binary) {
var rv = {};
// FIXME: stub
return rv;
},
};
7 changes: 7 additions & 0 deletions lib/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ exports.tables = {
MISSING: { name: 'Missing', value: 255 },
}),

// Code Table 5.1
OriginalFieldType: Object.freeze({
FLOAT: { name: 'Floating point', value: 0 },
INTEGER: { name: 'Integer', value: 1 },
MISSING: { name: 'Missing', value: 255 },
}),

// Code Table 6.0
BitMapIndicator: Object.freeze({
SPECIFIED: { name: 'Use specified bit-map', value: 0 },
Expand Down
30 changes: 30 additions & 0 deletions test/dataRepresentationTemplates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var assert = require('assert');
var grib = require('../index');
var files = require('./lib/fixtures').files;

describe('data representation template', function() {
var msgs = null;

describe('of ngm.grb', function() {
before(function(done) {
msgs = null;
grib.readUrl(files['ngm.grb'].url, function(err, msgs_) {
if(err) return done(err);
msgs = msgs_;
done();
});
});

it('should be template 0', function() {
var msg, field;
for(var m_idx in msgs) {
msg = msgs[m_idx];
for(var f_idx in msg.fields) {
field = msg.fields[f_idx];
assert.ok(field.representation.representation);
assert.strictEqual(0, field.representation.representation.templateNumber);
}
}
});
});
});