Skip to content

Commit

Permalink
v1.4.1
Browse files Browse the repository at this point in the history
Update VSOP2013.NET.csproj
fix XYZToLBR
code cleaning
Update DataConverter.csproj
  • Loading branch information
kingsznhone committed Jan 27, 2025
1 parent 2d21a77 commit 730821b
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 97 deletions.
16 changes: 8 additions & 8 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# static fields should have s_ prefix
dotnet_naming_rule.static_fields_should_have_prefix.severity = error
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static
dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected
dotnet_naming_style.static_prefix_style.required_prefix = s_
dotnet_naming_style.static_prefix_style.capitalization = camel_case
# dotnet_naming_rule.static_fields_should_have_prefix.severity = error
# dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
# dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
# dotnet_naming_symbols.static_fields.applicable_kinds = field
# dotnet_naming_symbols.static_fields.required_modifiers = static
# dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected
# dotnet_naming_style.static_prefix_style.required_prefix = s_
# dotnet_naming_style.static_prefix_style.capitalization = camel_case

# internal and private fields should be _camelCase
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = error
Expand Down
14 changes: 13 additions & 1 deletion DataConverter/DataConverter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,24 @@

<ItemGroup>
<PackageReference Include="FastLZMA2Net" Version="1.0.0" />
<PackageReference Include="MemoryPack" Version="1.21.1" />
<PackageReference Include="MemoryPack" Version="1.21.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\VSOP2013.NET\VSOP2013.NET.csproj" />
</ItemGroup>

<ItemGroup>
<None Remove="C:\Users\kings\.nuget\packages\fastlzma2net\1.0.0\build\x64\fast-lzma2.dll" />
</ItemGroup>

<ItemGroup>
<None Remove="C:\Users\kings\.nuget\packages\fastlzma2net\1.0.0\build\x64\fast-lzma2.dll" />
</ItemGroup>

<ItemGroup>
<None Remove="C:\Users\kings\.nuget\packages\fastlzma2net\1.0.0\build\x64\fast-lzma2.dll" />
</ItemGroup>


</Project>
8 changes: 4 additions & 4 deletions DataConverter/DataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class DataReader
/// <summary>
/// Mean Longitude J2000 (radian)
/// </summary>
private static readonly double[] s_ci0 =
private static readonly double[] _ci0 =
{
0.4402608631669000e1d,
0.3176134461576000e1d,
Expand All @@ -31,7 +31,7 @@ public static class DataReader
/// <summary>
/// Mean Motions in longitude (radian/cy)
/// </summary>
private static readonly double[] s_ci1 =
private static readonly double[] _ci1 =
{
0.2608790314068555e5d,
0.1021328554743445e5d,
Expand Down Expand Up @@ -214,8 +214,8 @@ private static Term ReadTerm(string line, ref Term T)

for (int j = 0; j < 17; j++)
{
T.aa += Bufferiphi[j] * s_ci0[j];
T.bb += Bufferiphi[j] * s_ci1[j];
T.aa += Bufferiphi[j] * _ci0[j];
T.bb += Bufferiphi[j] * _ci1[j];
}
return T;
}
Expand Down
46 changes: 26 additions & 20 deletions Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Demo
{
internal class Program
{
private static readonly Calculator s_vsop = new Calculator();
private static readonly Calculator _vsop = new Calculator();

private static async Task Main(string[] args)
{
Expand All @@ -34,27 +34,33 @@ private static async Task Main(string[] args)
VSOPResult_XYZ xyz;
VSOPResult_LBR lbr;

var debug = await s_vsop.GetPlanetPositionAsync(VSOPBody.EMB, vTime);
var debug = await _vsop.GetPlanetPositionAsync(VSOPBody.EMB, vTime);

var debug2 = await s_vsop.GetVariableAsync(VSOPBody.EMB, 0, vTime);
ell = s_vsop.GetPlanetPosition(VSOPBody.EMB, vTime);
var debug2 = await _vsop.GetVariableAsync(VSOPBody.EMB, 0, vTime);
ell = _vsop.GetPlanetPosition(VSOPBody.EMB, vTime);
FormattedPrint(ell, vTime);
//xyz = (VSOPResult_XYZ)ell;
//FormattedPrint(xyz, vTime);
//xyz.ReferenceFrame = ReferenceFrame.ICRSJ2000;
//FormattedPrint(xyz, vTime);

//lbr = (VSOPResult_LBR)ell;
//FormattedPrint(lbr, vTime);
//lbr.ReferenceFrame = ReferenceFrame.ICRSJ2000;
//FormattedPrint(lbr, vTime);
//for (int i = 0; i < 1000; i++)
//{
// foreach (VSOPBody body in Enum.GetValues(typeof(VSOPBody)))
// {
// ell = s_vsop.GetPlanetPosition(body, vTime);
// }
//}

double[] origin_XYZ = [-0.585386916046096, 0.7917314769504893, 3.5464737892804974E-06, -0.014120827616219243, -0.010294811978545626, 9.235246642556724E-09];
double[] converted_LBR = Utility.XYZtoLBR(origin_XYZ);
Console.WriteLine("Converted LBR Coordinates:");
Console.WriteLine($"L: {converted_LBR[0]}");
Console.WriteLine($"B: {converted_LBR[1]}");
Console.WriteLine($"R: {converted_LBR[2]}");
Console.WriteLine($"dL: {converted_LBR[3]}");
Console.WriteLine($"dB: {converted_LBR[4]}");
Console.WriteLine($"dR: {converted_LBR[5]}");
Console.WriteLine();

double[] origin_LBR = [2.207648105914849, 3.6023508314166335E-06, 0.9846415476671041, 0.017747319023700473, 7.438945360842563E-09, 0.00011725987886259545];
double[] converted_XYZ = Utility.LBRtoXYZ(origin_LBR);
Console.WriteLine("Converted XYZ Coordinates:");
Console.WriteLine($"X: {converted_XYZ[0]}");
Console.WriteLine($"Y: {converted_XYZ[1]}");
Console.WriteLine($"Z: {converted_XYZ[2]}");
Console.WriteLine($"dX: {converted_XYZ[3]}");
Console.WriteLine($"dY: {converted_XYZ[4]}");
Console.WriteLine($"dZ: {converted_XYZ[5]}");
Console.WriteLine();

Console.WriteLine("Press Enter to Start Performance Test...");
Console.ReadLine();
Expand Down
2 changes: 1 addition & 1 deletion EphemerisGenerator/EphemerisGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Platforms>x64</Platforms>
Expand Down
4 changes: 2 additions & 2 deletions EphemerisGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace EphemerisGenerator
{
internal class Program
{
private static Calculator s_calculator = new Calculator();
private static Calculator _calculator = new Calculator();

private static void Main(string[] args)
{
Expand All @@ -22,7 +22,7 @@ private static void Main(string[] args)
VSOPTime time = new VSOPTime(new DateTime(1900, 1, 1), TimeFrame.TDB);
while (time.TDB < enddate)
{
VSOPResult_ELL result = s_calculator.GetPlanetPosition(body, time);
VSOPResult_ELL result = _calculator.GetPlanetPosition(body, time);
sb.Clear();
sb.Append((int)body).Append(',').Append(time.J2000).Append(',');
sb.Append(string.Join(", ", result.Variables_ELL));
Expand Down
26 changes: 12 additions & 14 deletions VSOP2013.NET/Calculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public partial class Calculator
/// <summary>
/// //Planetary frequency in longitude
/// </summary>
private readonly double[] _freqpla =
private static readonly double[] _freqpla =
{
0.2608790314068555e5,
0.1021328554743445e5,
Expand All @@ -30,10 +30,10 @@ public Calculator()
{
//Import Planet Data
var assembly = Assembly.GetExecutingAssembly();
string datafilename = $"VSOP2013.NET.Resources.VSOP2013.BIN";
string dataFilename = $"VSOP2013.NET.Resources.VSOP2013.BIN";
using (MemoryStream recoveryStream = new MemoryStream())
{
using (Stream cs = assembly.GetManifestResourceStream(datafilename))
using (Stream cs = assembly.GetManifestResourceStream(dataFilename))
{
using (DecompressStream ds = new DecompressStream(cs))
{
Expand All @@ -56,9 +56,9 @@ public VSOPResult_ELL GetPlanetPosition(VSOPBody body, VSOPTime time)
return Coordinate;
}

public Task<VSOPResult_ELL> GetPlanetPositionAsync(VSOPBody body, VSOPTime time)
public ValueTask<VSOPResult_ELL> GetPlanetPositionAsync(VSOPBody body, VSOPTime time)
{
return Task.Run(() => GetPlanetPosition(body, time));
return new ValueTask<VSOPResult_ELL>(Task.Run(() => GetPlanetPosition(body, time)));
}

/// <summary>
Expand All @@ -72,9 +72,10 @@ public double GetVariable(VSOPBody body, int iv, VSOPTime time)
{
return Calculate(_vsop2013DATA[(int)body].variables[iv], time.J2000);
}
public Task<double> GetVariableAsync(VSOPBody body, int iv, VSOPTime time)

public ValueTask<double> GetVariableAsync(VSOPBody body, int iv, VSOPTime time)
{
return Task.Run(() => GetVariable(body, iv, time));
return new ValueTask<double>(Task.Run(() => GetVariable(body, iv, time)));
}

/// <summary>
Expand All @@ -97,25 +98,22 @@ private double Calculate(VariableTable Table, double JD2000)
}

double result = 0d;
double u, su, cu;
double xl;
Term[] terms;
for (int it = 0; it < Table.PowerTables.Length; it++)
{
if (Table.PowerTables[it].Terms == null) continue;
terms = Table.PowerTables[it].Terms;
for (int n = 0; n < terms.Length; n++)
{
u = terms[n].aa + terms[n].bb * tj;

su = Math.Sin(u);
cu = Math.Cos(u);

double u = terms[n].aa + terms[n].bb * tj;
double su = Math.Sin(u);
double cu = Math.Cos(u);
result += t[it] * (terms[n].ss * su + terms[n].cc * cu);
}
}
if (Table.Variable == VSOPVariable.L)
{
double xl;
xl = result + _freqpla[(int)Table.Body] * tj;
xl = (xl % Math.Tau + Math.Tau) % Math.Tau;
result = xl;
Expand Down
2 changes: 1 addition & 1 deletion VSOP2013.NET/DataStruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ public partial struct Term
[FieldOffset(24)]
public double bb;
}
}
}
Binary file removed VSOP2013.NET/Resources/NativeAccelerator.dll
Binary file not shown.
25 changes: 12 additions & 13 deletions VSOP2013.NET/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public static class Utility

if (cA != rB)
{
Console.WriteLine("Matrixes can't be multiplied!!");
return null;
throw new ArgumentException("Matrixes can't be multiplied!!");
}
else
{
Expand Down Expand Up @@ -89,7 +88,7 @@ public static double[] XYZtoLBR(double[] xyz)
//Sin(θ) = Cos(b), Cos(θ) = Sin(b)
b = Math.Asin(z / r);

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER

#region vector matrix mul

Expand All @@ -104,10 +103,10 @@ public static double[] XYZtoLBR(double[] xyz)
lbr[0] = l;
lbr[1] = b;
lbr[2] = r;
lbr[3] = Vector256.Sum(vv * v1);
lbr[4] = -Vector256.Sum(vv * v2);
lbr[5] = Vector256.Sum(vv * v3);
return lbr.ToArray();
lbr[3] = Vector256.Sum(v3 * vv);
lbr[4] = -Vector256.Sum(v2 * vv);
lbr[5] = Vector256.Sum(v1 * vv);
//return lbr.ToArray();
}

#endregion vector matrix mul
Expand Down Expand Up @@ -162,7 +161,7 @@ public static double[] LBRtoXYZ(double[] lbr)
y = r * Math.Cos(b) * Math.Sin(l);
z = r * Math.Sin(b);

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER

#region vector matrix mul

Expand All @@ -177,9 +176,9 @@ public static double[] LBRtoXYZ(double[] lbr)
xyz[0] = x;
xyz[1] = y;
xyz[2] = z;
xyz[3] = Vector256.Sum(vv * m1);
xyz[4] = Vector256.Sum(vv * m2);
xyz[5] = -Vector256.Sum(vv * m3);
xyz[3] = Vector256.Sum(m1 * vv);
xyz[4] = Vector256.Sum(m2 * vv);
xyz[5] = -Vector256.Sum(m3 * vv);
return xyz.ToArray();
}

Expand Down Expand Up @@ -310,7 +309,7 @@ public static double[] DynamicaltoICRS(double[] dynamical)
Sphi = Math.Sin(phi);
Cphi = Math.Cos(phi);

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
if (Vector256.IsHardwareAccelerated)
{
Vector256<double> r1 = Vector256.Create(Cphi, -Sphi * Ceps, Sphi * Seps, 0);
Expand Down Expand Up @@ -433,4 +432,4 @@ public static double[] ICRStoDynamical(double[] icrs)
return dynamical.ToArray();
}
}
}
}
Loading

0 comments on commit 730821b

Please sign in to comment.