从swedll32.dll调用swe_calc_ut()

时间:2013-06-03 06:46:10

标签: c# .net

我正在尝试使用c#中的swedll32.dll绘制出生图。当我首先使用dllimport调用函数swe_calc_ut()时,它给出了正确的结果。但如果我在此之前调用swedll32.dll的任何其他函数,之后调用swe_calc_ut(),则返回结果double []中的NaN值。 这是代码..

Main.cs

Class Main
{

UniversalTOBUTJD = Sweph.swe_julday(birthTimeUTC.Year, birthTimeUTC.Month,    
birthTimeUTC.Day, birthTimeUTC.TimeOfDay.TotalHours);
double[] tret = new Double[6] { 0, 0, 0, 0, 0, 0 };
Sweph.swe_calc_ut(UniversalTOBUTJD , 0, 0, tret);**/// this returns NaN in tret arrey**


}

如果我尝试如下:这里我使用硬编码值作为通用时间,我通过调用Sweph.swe_julday()函数获得

{

 Sweph.swe_calc_ut(2443436.659722222, 0, 0, tret); **/// this returns correct values in tret array**
 UniversalTOBUTJD = Sweph.swe_julday(birthTimeUTC.Year, birthTimeUTC.Month,    
 birthTimeUTC.Day, birthTimeUTC.TimeOfDay.TotalHours);
 double[] tret = new Double[6] { 0, 0, 0, 0, 0, 0 };

}

Sweph.cs 类Sweph {

   [DllImport("swedll32.dll", CharSet = CharSet.Ansi, EntryPoint = "swe_julday")]
    public extern static double xyz_swe_julday(int year, int month, int day, double hour, int gregflag);   //no

    /// <summary>
    /// swe_julday - It computes year, month, day and hour from a Julian day number
    /// </summary>
    /// <param name="year">Year</param>
    /// <param name="month">Month</param>
    /// <param name="day">Day</param>
    /// <param name="hour">Hour</param>
    /// <returns>Returns the Julian day</returns>
    public static double swe_julday(int year, int month, int day, double hour)
    {
        return xyz_swe_julday(year, month, day, hour, 1);
    }

    [DllImport("swedll32.dll", CharSet = CharSet.Ansi, EntryPoint = "swe_calc_ut")]
    private extern static int xyz_swe_calc_ut(double tjd_ut, int ipl, int iflag, 
    double[] xx, StringBuilder serr);

    /// <summary>
    /// swe_calc_ut - Compute a planet or other bodies
    /// </summary>
    /// <param name="tjd_ut">Julian day, Universal Time</param>
    /// <param name="ipl">planet number</param>
    /// <param name="addFlags">a 32bit integercontaining bit flags that indicate what kind of computation wanted</param>
    /// <param name="xx">array of 6 doubles for Longitude,latitude,distance,speed in long, speed in lat and speed in dist</param>
    //public static void getPlanet(double tjd_ut, int ipl, int addFlags, double[] xx)
  public static void swe_calc_ut(double tjd_ut, int ipl, int addFlags, double[] xx)
    {

        StringBuilder serr = new StringBuilder(256);

        int ret = xyz_swe_calc_ut(tjd_ut, ipl, iflag | addFlags, xx, serr);

    }

}

请帮助我真的卡在这里。

1 个答案:

答案 0 :(得分:0)

在调用swe_calc_ut之前,您应该设置一个包含以下数据的文件夹的路径:

[DllImport("swedll32.dll", CharSet = CharSet.Ansi, EntryPoint = "swe_set_ephe_path")]
private static extern void swe_set_ephe_path(String swe_path);

swe_set_ephe_path(@"c:\path\to\ephe\");