ygrenier / SwissEphNet

Swiss Ephemeris for .Net. A Swiss Ephemeris portage for .Net.
Other
77 stars 35 forks source link

swe_nod_aps gives wrong values for lunar nodes (maybe others but only tested moon.) #42

Open jzarech opened 4 years ago

jzarech commented 4 years ago

Hi Yan,

I'm using your .Net library and I noticed that swe_nod_aps is getting a different answer than the dll provided by swiss ephemeris --

I ran both side by side but I can't step into the DLL code to see where they deviate but here's the params I'm passing in and the output --

Everything else works perfectly so far.

I know you don't get paid for this but is it possible you could try this code on your end to verify?

This is the call that's failing: Ret_Flag = _sweph.swe_nod_aps(TJDE, intplanet, iflag, SE_NODBIT_MEAN, xnAsc, xnDesc, xnPeri, xnAphe, strErr)

TJDE 2439970.3805555557

Planet=1

iflag=258

method=1

xnAsc first value: 214.00080139962134

xnDsc first value: 213.92002008102247

Using sweph dll with same input I get this output: xnAsc first value: 17.967 xnDsc first value: 197.96

the sweph dll values are correct.

Thanks,

Joseph error_screen_shot

I have a project but couldn't upload the zip --

Here's the code to reproduce -- email me for zipped project if you want/need it --

using SwissEphNet; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace swe_nod_aps_error { class Program { static SwissEphNet.SwissEph _sweph; static bool bIsSwephInitialized = false;

    static Program()
    {
        _sweph = new SwissEphNet.SwissEph();

        _sweph.OnLoadFile += sweph_OnLoadFile;

        _sweph.swe_set_ephe_path("C:\\swe_nod_aps_error_ephe\\");

        bIsSwephInitialized = true;

    }

    static private void sweph_OnLoadFile(object sender, LoadFileEventArgs e)
    {
        if (e.FileName.StartsWith("[ephe]"))
        {
            e.File = SearchFile(e.FileName.Replace("[ephe]", string.Empty));
        }
        else
        {
            var f = e.FileName;
            if (System.IO.File.Exists(f))
                e.File = new System.IO.FileStream(f, System.IO.FileMode.Open, System.IO.FileAccess.Read);
        }
    }

    static private Stream SearchFile(String fileName)
    {
        //I changed this code ja 1/16/2020 so make sure it works.
        string startupPath = System.Reflection.Assembly.GetExecutingAssembly().Location;

        fileName = fileName.Trim('/', '\\');
        var folders = new string[] {
            System.IO.Path.Combine(startupPath, "Datas"),
            @"C:\sweph\ephe"
        };
        foreach (var folder in folders)
        {
            var f = Path.Combine(folder, fileName);
            if (File.Exists(f))
                return new System.IO.FileStream(f, System.IO.FileMode.Open, System.IO.FileAccess.Read);
        }
        return null;
    }

    static void Main(string[] args)
    {
        int intRetVal=0;
        double TJDE = 2439970.3805555557;
        int intPlanet = 1; //Moon
        int iFlag = 258; // Swiss Eph and Speed
        int iMethod = 1;

        double[] xnAsc = new double[6];
        double[] xnDesc = new double[6];
        double[] xnPeri = new double[6];
        double[] xnAphe = new double[6];
        string strErr = new string(Convert.ToChar(0),255);

        intRetVal = _sweph.swe_nod_aps(TJDE, intPlanet, iFlag, iMethod, xnAsc, xnDesc, xnPeri, xnAphe,ref strErr);

        //Assert that .Net Version matches Swiss Eph DLL values (which are correct and verified via Ephemeris).
        System.Diagnostics.Debug.Assert(xnAsc[0] == 17.967, "Moon's North Node should be: 17.967");
        System.Diagnostics.Debug.Assert(xnDesc[0] == 197.96, "Moon's South Node should be: 197.96");

    }
}

}

rpuig commented 2 years ago

hello, do you know how to use swetest.c to calculate lunar nodes?