Last active
October 14, 2019 02:58
-
-
Save tmizu23/ca84816d3fcbabd34e515c7c0ecfa951 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////// | |
// 2019.10.11 Ver1.02 | |
// | |
// pos2LatLonAlt.js | |
// | |
// Usage: | |
// convert pos file to Lat Lon Alt csv file. | |
// output value is median of fix value. | |
// drag and drop pos file to pos2LatLonAlt.js, the csv file will be output to the same folder of pos file. | |
///////////////////////////////////////// | |
//calc array median | |
var median = function(numbers) { | |
var median = 0, numsLen = numbers.length; | |
numbers.sort(); | |
if (numsLen % 2 === 0) { | |
median = (numbers[numsLen / 2 - 1]*1.0 + numbers[numsLen / 2]*1.0) / 2; | |
} else { | |
median = numbers[(numsLen - 1) / 2]; | |
} | |
return median; | |
}; | |
//main | |
var outf; | |
for(var i=0;i<WScript.Arguments.Count();i++){ | |
var lat_arr =[]; | |
var lon_arr =[]; | |
var alt_arr =[]; | |
var cnum = 1; | |
var input = WScript.Arguments(i); | |
var output = input.replace(".pos",".csv"); | |
var name = input.split('\\').pop(); | |
var fs = new ActiveXObject ("Scripting.FileSystemObject"); | |
var inf = fs.OpenTextFile (input, 1); | |
if(!outf){ | |
outf = fs.CreateTextFile (output, true); | |
outf.WriteLine("name,lat,lon,alt"); | |
} | |
do { | |
var csvdata = inf.ReadLine().replace(/^\s+|\s+$/g,'').replace(/ +/g,' ').split (' '); | |
if (cnum >= 25) { // skip pos header | |
if (csvdata[5] == 1) { // fillter fix value | |
lat_arr.push(csvdata[2]) | |
lon_arr.push(csvdata[3]) | |
alt_arr.push(csvdata[4]) | |
//outf.WriteLine (csvdata[2] + " " + csvdata[3] + " " + csvdata[4]+ " " + csvdata[5]); //for debug | |
} | |
} | |
cnum++; | |
}while (inf.AtEndOfStream == false); | |
outf.WriteLine(name + "," + median(lat_arr) + "," + median(lon_arr) + "," + median(alt_arr)); | |
inf.Close (); | |
} | |
outf.Close (); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment