<commit_before>var fs = require('fs'),
    xml2js = require('xml2js'),
    handlebars = require("handlebars");

var xml = fs.readFileSync('./track.xml', 'utf-8');

//console.log('Source XML:');
//console.log(xml);

var name, when, coord, num;

xml2js.parseString(xml, function (err, result) {
    console.log('Parsed Json:');
    var data = result.kml.Document[0].Placemark[2]['gx:Track'];
    
    name = result.kml.Document[0].Placemark[2].name[0];    
    when = data[0].when;
    coord = data[0]['gx:coord'];
    num = when.length;
    
//    console.log(when, coord, num);
});


/* Prepare data for handlebar template */
var template = fs.readFileSync('./gpx.handlebars', 'utf-8');
template = handlebars.compile(template);

var data = {
    name: name,
    coor: []
};

for (i=0; i<num; i++){
    var coo = coord[i].split(' ');
    
    data.coor[i] = {
        time: when[i],
        lon: coo[0],
        lat: coo[1],
        height: coo[2]
    }
};

var buffer = template(data);
//console.log(buffer);

fs.writeFile('./track.gpx', buffer, function(err) {
    if (err) {
        console.log(err);
    } else {
        console.log("file saved");
    }
});<commit_msg>get filename from command line arguments<commit_after>var fs = require('fs'),
    xml2js = require('xml2js'),
    handlebars = require("handlebars");


var filename = process.argv[2];
var filename_unext = filename.split('.')[0];

var xml = fs.readFileSync(filename, 'utf-8');

//console.log('Source XML:');
//console.log(xml);

var name, when, coord, num;

xml2js.parseString(xml, function (err, result) {
    var data = result.kml.Document[0].Placemark[2]['gx:Track'];
    
    name = result.kml.Document[0].Placemark[2].name[0];    
    when = data[0].when;
    coord = data[0]['gx:coord'];
    num = when.length;
    
//    console.log(when, coord, num);
});


/* Prepare data for handlebar template */
var template = fs.readFileSync('./gpx.handlebars', 'utf-8');
template = handlebars.compile(template);

var data = {
    name: name,
    coor: []
};

for (i=0; i<num; i++){
    var coo = coord[i].split(' ');
    
    data.coor[i] = {
        time: when[i],
        lon: coo[0],
        lat: coo[1],
        height: coo[2]
    }
};

var buffer = template(data);
//console.log(buffer);

fs.writeFile(filename_unext + '.gpx', buffer, function(err) {
    if (err) {
        console.log(err);
    } else {
        console.log("file saved as " + filename_unext + '.gpx');
    }
});
{'fraction_non_alphanumeric': 0.19535073409461665, 'fraction_numerical': 0.013866231647634585, 'mean_word_length': 2.9310897435897436, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 13}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3716259', 'n_tokens_mistral': 893, 'n_tokens_neox': 893, 'n_words': 181}