Skip to content

Commit

Permalink
Fixed broken getTimedModel method.
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonreavis committed Mar 22, 2015
1 parent 2941b87 commit 688fc21
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
7 changes: 1 addition & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ var Model = require('./lib/model.js');
var geomagnetism = module.exports = {};

var base_model;
var models = {};

geomagnetism.model = function(date) {
date = date || new Date();
var key = date.toDateString();
if (!base_model) {
base_model = new Model();
}
if (!models[key]) {
models[key] = base_model.getTimedModel(date);
}
return models[key];
return base_model.getTimedModel(date);
};
4 changes: 3 additions & 1 deletion lib/parsers/cof.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = function(str){
main_field_coeff_h: [0],
secular_var_coeff_g: [0],
secular_var_coeff_h: [0],
n_max: 0
n_max: 0,
n_max_sec_var: 0
};
var lines = str.split(/\r?\n/);
for(var i = 0; i < lines.length; i++) {
Expand All @@ -31,6 +32,7 @@ module.exports = function(str){
}
if(n > result.n_max){
result.n_max = n;
result.n_max_sec_var = n;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "geomagnetism",
"version": "0.0.1",
"version": "0.0.2",
"description": "Computes geomagnetic field information",
"main": "index.js",
"scripts": {
Expand Down
24 changes: 17 additions & 7 deletions test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ var path = require('path');
var fs = require('fs');

var tolerances = {
incl: 1, //deg
decl: 2, //deg
x: 250, //nT
y: 250, //nT
z: 250, //nT
h: 250, //nT
f: 250 //nT
incl: 0.01, //deg
decl: 0.01, //deg
x: 5, //nT
y: 5, //nT
z: 5, //nT
h: 5, //nT
f: 5 //nT
};

function loadTestValues(){
Expand Down Expand Up @@ -67,5 +67,15 @@ describe("model", function(){
geomagnetism.model(new Date("1/1/1999"));
}, RangeError);
});
it("should get a different model for a different date", function(){
var pt = [44.53461, -109.05572];
var model0 = geomagnetism.model();
var model1 = geomagnetism.model(new Date("3/22/2018"));
var decl0 = model0.point(pt).decl;
var decl1 = model1.point(pt).decl;
assert.notEqual(model0, model1);
assert(Math.abs(decl1 - decl0) > 0.001, 'declination should be different');
});

});
});
1 change: 1 addition & 0 deletions wmm.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@
0
],
"n_max": 12,
"n_max_sec_var": 12,
"epoch": 2015,
"name": "WMM-2015",
"start_date": "2014-12-15T07:00:00.000Z",
Expand Down

0 comments on commit 688fc21

Please sign in to comment.