-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
58 lines (55 loc) · 1.91 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src='//code.jquery.com/jquery-2.0.3.min.js'></script>
<script src='lib/knockout.js'></script>
<script src='netcdf3.js'></script>
</head>
<body>
<tr>
<td><input data-bind="event: { change: loadVariables }" type="file" id="netcdfFile"/></td>
<td><select data-bind="options: variables, value: selectedVar"></select></td>
<td><button data-bind="click: showVariable, enable: ncFile()">Display</button></td>
</tr>
<div data-bind="text: variableData"></div>
<script>
var NcFile = window.netcdf3.NcFile;
var variables = ko.observableArray([]);
var viewModel = {
ncFile: ko.observable(''),
variables: variables,
selectedVar: ko.observable(''),
variableData: ko.observable('')
};
viewModel.loadVariables = function () {
var file = $('input#netcdfFile')[0].files[0];
if (file === undefined) { return; }
NcFile.read(file, function (nc) {
var i;
viewModel.ncFile(nc);
if (nc.constructor !== NcFile) {
viewModel.ncFile('');
alert("Could not open file: " + file.name);
}
variables.removeAll();
for (i in nc.variables) {
variables.push(i);
}
});
};
viewModel.showVariable = function () {
var vName = this.selectedVar();
var v = this.ncFile().variables[vName];
v.read(function (d) {
if(typeof d === 'string') {
viewModel.variableData(d);
} else {
viewModel.variableData(v.toString());
}
});
}.bind(viewModel);
ko.applyBindings(viewModel);
</script>
</body>
</html>