-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 27bc341
Showing
7 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
bin/ | ||
obj/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mps2asc", "mps2asc\mps2asc.csproj", "{FE61F52C-A24F-425A-9598-98A03D708CA9}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{FE61F52C-A24F-425A-9598-98A03D708CA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FE61F52C-A24F-425A-9598-98A03D708CA9}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FE61F52C-A24F-425A-9598-98A03D708CA9}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FE61F52C-A24F-425A-9598-98A03D708CA9}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"sdk": { | ||
"version": "6.0", | ||
"rollForward": "latestMajor", | ||
"allowPrerelease": true | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Xml; | ||
|
||
namespace mps2asc | ||
{ | ||
public static class MpsParser | ||
{ | ||
public static List<Point> ParseXml(string path) | ||
{ | ||
XmlDocument doc = new(); | ||
doc.Load(path); | ||
|
||
var points = new List<Point>(); | ||
|
||
var nodes = doc.DocumentElement?.SelectSingleNode("/point_set_file/point_set/time_series")?.SelectNodes("point"); | ||
if (nodes != null) | ||
{ | ||
foreach (XmlNode n in nodes) | ||
{ | ||
var xNode = n.SelectSingleNode("x"); | ||
var yNode = n.SelectSingleNode("y"); | ||
var zNode = n.SelectSingleNode("z"); | ||
|
||
if (xNode != null && yNode != null && zNode != null) | ||
{ | ||
var x = double.Parse(xNode.InnerText, CultureInfo.InvariantCulture); | ||
var y = double.Parse(yNode.InnerText, CultureInfo.InvariantCulture); | ||
var z = double.Parse(zNode.InnerText, CultureInfo.InvariantCulture); | ||
points.Add(new Point(x,y,z)); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Point not matching expected structure..."); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Document not matching expected structure..."); | ||
} | ||
|
||
return points; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Globalization; | ||
|
||
namespace mps2asc | ||
{ | ||
public class Point | ||
{ | ||
public Point(double x, double y, double z) | ||
{ | ||
X = x; | ||
Y = y; | ||
Z = z; | ||
} | ||
|
||
public double X { get; } | ||
public double Y { get; } | ||
public double Z { get; } | ||
|
||
public override string ToString() | ||
{ | ||
return $"{X.ToString(CultureInfo.InvariantCulture)} {Y.ToString(CultureInfo.InvariantCulture)} {Z.ToString(CultureInfo.InvariantCulture)}"; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using mps2asc; | ||
|
||
class Program | ||
{ | ||
static void Main() | ||
{ | ||
var args = Environment.GetCommandLineArgs(); | ||
string path = ""; | ||
if (args.Length >= 2) | ||
{ | ||
path = args[1]; | ||
} | ||
|
||
while (!File.Exists(path)) | ||
{ | ||
Console.WriteLine("Couldn't find the file. Please enter the path to the file (e.g. 'C:\\Users\\X\\Desktop\\file.mps')"); | ||
path = Console.ReadLine() ?? string.Empty; | ||
} | ||
var outputFile = Path.ChangeExtension(path, "asc"); | ||
|
||
var points = MpsParser.ParseXml(path); | ||
|
||
if (points.Count == 0) | ||
{ | ||
Console.WriteLine("Apparently, something went wrong parsing..."); | ||
Console.Read(); | ||
} | ||
else | ||
{ | ||
var stringifyPoints = points.Select(p => p.ToString()); | ||
File.WriteAllLines(outputFile, stringifyPoints); | ||
|
||
Console.WriteLine($"{points.Count} points written to {outputFile}"); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |