Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions GnuPlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Threading;
using System.Linq;
using System.Globalization;

namespace AwokeKnowing.GnuplotCSharp
{
Expand Down Expand Up @@ -374,15 +375,15 @@ public static void SPlot(List<StoredPlot> storedPlots)
public static void WriteData(double[] y, StreamWriter stream, bool flush = true)
{
for (int i = 0; i < y.Length; i++)
stream.WriteLine(y[i].ToString());
stream.WriteLine(y[i].ToString(CultureInfo.InvariantCulture));

if (flush) stream.Flush();
}

public static void WriteData(double[] x, double[] y, StreamWriter stream, bool flush = true)
{
for (int i = 0; i < y.Length; i++)
stream.WriteLine(x[i].ToString() + " " + y[i].ToString());
stream.WriteLine(x[i].ToString(CultureInfo.InvariantCulture) + " " + y[i].ToString(CultureInfo.InvariantCulture));

if (flush) stream.Flush();
}
Expand All @@ -393,7 +394,7 @@ public static void WriteData(int ySize, double[] z, StreamWriter stream, bool fl
{
if (i > 0 && i % ySize == 0)
stream.WriteLine();
stream.WriteLine(z[i].ToString());
stream.WriteLine(z[i].ToString(CultureInfo.InvariantCulture));
}

if (flush) stream.Flush();
Expand All @@ -408,7 +409,7 @@ public static void WriteData(double[,] zz, StreamWriter stream, bool flush = tru
{
line = "";
for (int j = 0; j < n; j++)
line += zz[i, j].ToString() + " ";
line += zz[i, j].ToString(CultureInfo.InvariantCulture) + " ";
stream.WriteLine(line.TrimEnd());
}

Expand All @@ -423,7 +424,8 @@ public static void WriteData(double[] x, double[] y, double[] z, StreamWriter st
{
if (i > 0 && x[i] != x[i - 1])
stream.WriteLine("");
stream.WriteLine(x[i] + " " + y[i] + " " + z[i]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string.Format accepts CultureInfo, no need to call ToString for every parameter
string.Format(CultureInfo.InvariantCulture, "{0} {1} {2}", x[i], y[i], z[i]);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's nifty! Didn't like that line at all but didn't think about any other way to do it. Thanks! Fixed.

stream.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0} {1} {2}", x[i], y[i], z[i]));
}

if (flush) stream.Flush();
Expand Down