-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
116 lines (88 loc) · 2.57 KB
/
index.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env node
var Dissolve = require("dissolve");
var nominal_case_size;
var i = 1;
var parser = Dissolve();
// Parse header information
parser.tap('header', function() {
this.string('rec_type', 4);
this.string('prod_name', 60);
this.int32('layout_code');
this.int32('nominal_case_size');
this.int32('compressed');
this.int32('weight_index');
this.int32('ncases');
this.doublele('bias');
this.string('creation_date', 9);
this.string('creation_time', 8);
this.string('file_label', 64);
this.buffer('padding', 3);
}).tap(function () {
nominal_case_size = this.vars.header.nominal_case_size;
});
// Parse variables
parser.loop('variables', function (end) {
this.int32('record_type_code').tap(function () {
if (this.vars.variable_type_code !== -1) {
this.int32('variable_type_code');
this.int32('has_label');
this.int32('n_missing');
this.int32('print_format');
this.int32('write_format');
this.string('varname', 8).tap(function () {
if (this.vars.has_label === 1) {
this.int32('label_length').tap(function () {
this.string('variable_label', Math.ceil(this.vars.label_length/4.0) * 4);
});
}
if (this.vars.n_missing !== 0) {
this.buffer('missings', this.vars.n_missing * 64);
}
});
} else {
this.buffer('ignore', 24);
}
});
if (i++ == nominal_case_size) {
end()
}
});
var count;
parser.tap('remaining_dict', function () {
this.int32('rec_type');
this.tap('value_label_records', function () {
if (this.vars.rec_type === 3) {
var j = 1;
this.int32('count').loop('value_labels', function (end) {
this.doublele('value', 8);
this.uint8('label_length');
this.tap(function () {
var round_label_length,
tmp_mod = (this.vars.label_length+1) % 8;
if (tmp_mod !== 0) {
round_label_length = this.vars.label_length + 8 - tmp_mod;
} else {
round_label_length = this.vars.label_length;
}
this.string('label', round_label_length);
});
if (j++ == this.vars.count) {
end();
}
});
}
});
this.tap('value_label_variables', function () {
this.int32('rec_type_2');
this.int32('var_count');
})
if (this.vars.rec_type === 6) {
} else if (this.vars.rec_type === 7) {
} else if (this.vars.rec_type === 999) {
}
});
parser.tap(function () {
// Enable this to see what is going on
console.log(this.vars.remaining_dict);
});
module.exports = parser;