Loading ...
Sorry, an error occurred while loading the content.

Re: Fwd: RE:calling swe_rise_trans()

Expand Messages
  • Someshwar U
    Dear all, I have worked out the problem (c#)please check it and mail me if u have any doubts. using System; using System.Collections.Generic; using
    Message 1 of 17 , May 12, 2012
    View Source
    • 0 Attachment
      Dear all,

      I have worked out the problem (c#)please check it and mail me if u have
      any doubts.

      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;
      using System.Runtime.InteropServices;
      namespace WindowsFormsApplication1
      {
      public partial class Form1 : Form
      {
      public double jd;
      public double sunrise;
      public double[] geopos=new double[3] {80.00,18.00,0.00};
      double[] tret = new Double[6] {0,0,0,0,0,0};
      int iyear = 1975;
      int imonth = 02;
      int iday = 22;
      int ihour = 19;
      int imin = 44;
      int isec = 00;
      double btime = 0.00;
      public double toDouble()
      {
      if (btime >= 0)
      return (((double)ihour) + (((double)imin) / 60.0) + (((double)isec) /
      3600.0));
      else
      return (((double)ihour) - (((double)imin) / 60.0) - (((double)isec) /
      3600.0));



      }
      public Form1()
      {
      InitializeComponent();
      }
      public static int SEFLG_SWIEPH = 2;
      public static int SEFLG_TRUEPOS = 16;
      public static int SEFLG_SPEED = 256;
      public static int SEFLG_SIDEREAL = 64 * 1024;
      public static int iflag = SEFLG_SWIEPH | SEFLG_SPEED | SEFLG_SIDEREAL;
      public static int SE_CALC_RISE = 1;
      public static int SE_CALC_SET = 2;

      [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);

      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_rise_trans")]
      private extern static int xyz_swe_rise_trans (double tjd_ut, int ipl,
      string starname, int epheflag, int rsmi, double[] geopos, double
      atpress, double attemp, double[] tret, StringBuilder serr);

      public static void swe_rise(double tjd_ut, int ipl, int rsflag, double[]
      geopos, double atpress, double attemp, double[] tret)
      {

      StringBuilder serr = new StringBuilder(256);
      int ret = xyz_swe_rise_trans(tjd_ut, ipl, "", iflag, SE_CALC_RISE |
      rsflag
      , geopos, atpress, attemp, tret, serr);
      }

      private void button1_Click(object sender, EventArgs e)

      {

      jd = xyz_swe_julday(iyear, imonth, iday, toDouble(), 1);
      swe_rise (jd, 0, 1, geopos, 0.0, 0.0, tret);
      sunrise =tret[0];
      MessageBox .Show( jd.ToString());
      button1.Text=sunrise .ToString ();

      }

      }
      }

      the julianday i got is 2442466.32222222

      the sunrise i got for 80e longitude and 18 north lattitude is
      244246654379852

      Thank you all

      This is my first post

      please ingore any langauge mistakes

      Someshwar

      hyderabad,India
























      --- In swisseph@yahoogroups.com, "Utaro" <utaro@...> wrote:
      >
      > Thi s is the result I'm getting. C# VS 2010 .Net 4.0
      >
      >
      >
      >
      >
      >
      >
      > From: swisseph@yahoogroups.com [mailto:swisseph@yahoogroups.com] On
      Behalf
      > Of Utaro
      > Sent: Friday, May 11, 2012 10:16 PM
      > To: swisseph@yahoogroups.com
      > Subject: RE: [SWISSEPH] Re: Fwd: RE:calling swe_rise_trans()
      >
      >
      >
      >
      >
      > I have but same result. Ty.
      >
      > -----Original Message-----
      > From: swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
      > [mailto:swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com> ]
      On
      > Behalf
      > Of Francois Rouleau
      > Sent: Friday, May 11, 2012 9:50 PM
      > To: swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
      > Subject: Re: [SWISSEPH] Re: Fwd: RE:calling swe_rise_trans()
      >
      > have you tried?
      >
      > [DllImport("swedll32.dll", CharSet = CharSet.Ansi, EntryPoint =
      > "_swe_rise_trans@52")]
      > private extern static Int32 swe_rise_trans(double tjd_ut, Int32
      > ipl, string starname, Int32 epheflag, Int32 rsmi, double[] geopos,
      double
      > atpress, double attemp, ref double riseSetTime , string serr);
      >
      > On Fri, May 11, 2012 at 9:47 PM, Utaro utaro@...
      > <mailto:utaro%40astrotrader.com> > wrote:
      >
      > > **
      > >
      > >
      > > Hello Francois
      > > Thanks for the suggestion. I tried it but with no result. It seems
      that
      > > setting the CharSet to Unicode can include ansi but not the other
      way
      > > around
      > > and in this case it does not affect the calling procedure.
      > > Best Utaro
      > >
      > >
      > > -----Original Message-----
      > > From: swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
      > [mailto:swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com> ]
      On
      > Behalf
      > > Of Francois Rouleau
      > > Sent: Friday, May 11, 2012 7:55 PM
      > > To: swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
      > > Subject: Re: [SWISSEPH] Re: Fwd: RE:calling swe_rise_trans()
      > >
      > > I wonder if using "CharSet = CharSet.Ansi" instead of "CharSet =
      > > CharSet.Unicode" in your attribute could solve your problem?
      > >
      > > Francois
      > >
      > > On Fri, May 11, 2012 at 8:42 PM, Utaro utaro@...
      > <mailto:utaro%40astrotrader.com> > wrote:
      > >
      > > > **
      > >
      > > >
      > > >
      > > > Yes, char and string are obviously different type but in C# or VBA
      what
      > > is
      > > > used in C as char* can be declared as string and works fine. If I
      > > remember
      > > > correctly, I first declared serr as char in C# then the compiler
      threw
      > an
      > > > exception. So then tried the string and it worked. A good example
      is the
      > > > widely used swe_calc() function. The serr is declared as string in
      both
      > > VBA
      > > > or C# and it works.
      > > >
      > > > Once I get some kind of argument exception by able to call the dll
      at
      > > > least it is a good sign because it is a proof that C# is calling
      the dll
      > > > function but right now I can't reach to that stage getting an
      error
      > > message
      > > > stating "unable to find entry point name _swe_rise_trans@52 in
      > > > swedll32.dll".
      > > >
      > > > My current logic is to check the source and if it proves to take
      too
      > long
      > > > to accomplish my project then I will work around by writing a
      library
      > > > looking for a conjunction or opposition of planetary bodies to the
      ASC
      > > and
      > > > MC
      > > >
      > > > Ty.
      > > >
      > > >
      > > > Utaro
      > > >
      > > > From: swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
      > [mailto:swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com> ]
      On
      > > > Behalf Of Alois Treindl
      > > > Sent: Friday, May 11, 2012 4:54 PM
      > > > To: swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
      > > > Subject: Re: [SWISSEPH] Re: Fwd: RE:calling swe_rise_trans()
      > > >
      > > >
      > > > I was wrong, had jumped to the next function when reading the
      docu.
      > > > *tret is a pointer to just one double.
      > > >
      > > > On 11.05.12 23:31, astropalaver wrote:
      > > > >
      > > > >
      > > > >
      > > > > I hope that "*tret" isn't really supposed to be an array of 20
      > doubles!
      > > > >
      > > > > I've been passing the address of a double and it seems to work
      just
      > > > fine. I can't imagine what the other doubles might hold! I'll have
      to
      > > check
      > > > the source code.
      > > > >
      > > > >> From the docs: 6.10.swe_rise_trans()
      > > > >
      > > > > double *tret, /* return address (double) for rise time etc. */
      > > > >
      > > > > Thanks for the wonderful dll!
      > > > >
      > > > > Jay
      > > >
      > > > [Non-text portions of this message have been removed]
      > > >
      > > >
      > > >
      > >
      > > [Non-text portions of this message have been removed]
      > >
      > > ------------------------------------
      > >
      > > Yahoo! Groups Links
      > >
      > >
      > >
      >
      > [Non-text portions of this message have been removed]
      >
      > ------------------------------------
      >
      > Yahoo! Groups Links
      >
      > [Non-text portions of this message have been removed]
      >
      >
      >
      >
      >
      > [Non-text portions of this message have been removed]
      >
    • Utaro
      Problem solved with a bit of embarrassment. I was using an older swedll32.dll with 348,160 bytes. The latest version from
      Message 2 of 17 , May 12, 2012
      View Source
      • 0 Attachment
        Problem solved with a bit of embarrassment.

        I was using an older swedll32.dll with 348,160 bytes.
        The latest version from http://www.astro.com/ftp/swisseph/programs/ is
        491,520.
        Dependency Walker was able to pick up the entry point for swe_rise_trans()
        with the newer version.

        Thanks for various suggestions and help from Francois and Someshwar.

        What I learned from this:

        1. Never assume that you have the latest version of whatever you are dealing
        with.

        2. Because I am running my app in Unicode when the P/Invoke CharSet is set
        to Ansi the program crashes due to wrong memory allocation per byte. Because
        it occurs in between bridging from unmanaged to managed code the compiler
        may not throw an exception for this particular instance and simply crashes.

        Thank you all and great Mothers Day. Its deep when I think every human
        beings were born from mother and not father. Their influence is so great.
        Utaro


        -----Original Message-----
        From: swisseph@yahoogroups.com [mailto:swisseph@yahoogroups.com] On Behalf
        Of Francois Rouleau
        Sent: Friday, May 11, 2012 11:55 PM
        To: swisseph@yahoogroups.com
        Subject: Re: [SWISSEPH] Re: Fwd: RE:calling swe_rise_trans()

        I Can't see the image...but

        I tested the following ...and it work for me in VS 2010
        for Net framework 3.5 and 4.0


        ========================
        In form1:
        ========================

        private void button1_Click(object sender, EventArgs e)
        {
        Calc c = new Calc();

        int i = c.getRise();

        }

        =======================
        I created a class Calc:
        ========================

        using System;
        using System.Runtime.InteropServices;


        namespace CSharpAstro
        {

        public class Calc
        {

        public const int SE_JUL_CAL = 0;
        public const int SE_GREG_CAL = 1;
        public const int SE_SUN = 0;



        public Calc()
        {
        // constructor...
        }


        [DllImport("swedll32.dll", CharSet = CharSet.Ansi, EntryPoint =
        "_swe_rise_trans@52")]
        private extern static Int32 swe_rise_trans(double tjd_ut, Int32
        ipl, string starname, Int32 epheflag, Int32 rsmi, double[] geopos, double
        atpress, double attemp, ref double tret, string serr);


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

        public static double getJD(int year, int month, int day, double
        hour, int cal) {
        return ext_swe_julday(year, month, day, hour, cal);
        }

        public int getRise()
        {
        int retVal = 0;
        int SE_SUN = 0;
        string sErr = "";
        int iPlanetNo = SE_SUN;
        string sStarName = "";
        int iFlag = 0;
        double dReturn=0.0f;
        double dResult = 0;

        double[] dGeoPos = new double[3] { 74, 34, 0 };

        double dJd = 0;

        int SE_CALC_RISE = 1;
        dJd = getJD(2012, 5, 12, 0, 0);

        swe_rise_trans(dJd, iPlanetNo, sStarName, iFlag, SE_CALC_RISE,
        dGeoPos, 0.0f, 0.0f, ref dReturn, sErr);

        dResult = dReturn;

        return retVal;

        }


        }
        }



        On Sat, May 12, 2012 at 12:00 AM, Utaro <utaro@...> wrote:

        > **
        >
        >
        > In case the previous message doesn't make sense I have sent an image of
        the
        > error but it has been removed by the Yahoo server.
        >
        >
        > From: swisseph@yahoogroups.com [mailto:swisseph@yahoogroups.com] On Behalf
        > Of Utaro
        > Sent: Friday, May 11, 2012 10:58 PM
        >
        > To: swisseph@yahoogroups.com
        > Subject: RE: [SWISSEPH] Re: Fwd: RE:calling swe_rise_trans()
        >
        > Thi s is the result I'm getting. C# VS 2010 .Net 4.0
        >
        > From: swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
        > [mailto:swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com> ] On
        > Behalf
        > Of Utaro
        > Sent: Friday, May 11, 2012 10:16 PM
        > To: swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
        > Subject: RE: [SWISSEPH] Re: Fwd: RE:calling swe_rise_trans()
        >
        > I have but same result. Ty.
        >
        > -----Original Message-----
        > From: swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
        > <mailto:swisseph%40yahoogroups.com>
        > [mailto:swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
        > <mailto:swisseph%40yahoogroups.com> ] On
        > Behalf
        > Of Francois Rouleau
        > Sent: Friday, May 11, 2012 9:50 PM
        > To: swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
        > <mailto:swisseph%40yahoogroups.com>
        > Subject: Re: [SWISSEPH] Re: Fwd: RE:calling swe_rise_trans()
        >
        > have you tried?
        >
        > [DllImport("swedll32.dll", CharSet = CharSet.Ansi, EntryPoint =
        > "_swe_rise_trans@52")]
        > private extern static Int32 swe_rise_trans(double tjd_ut, Int32
        > ipl, string starname, Int32 epheflag, Int32 rsmi, double[] geopos, double
        > atpress, double attemp, ref double riseSetTime , string serr);
        >
        > On Fri, May 11, 2012 at 9:47 PM, Utaro <utaro@...
        > <mailto:utaro%40astrotrader.com>
        > <mailto:utaro%40astrotrader.com> > wrote:
        >
        > > **
        > >
        > >
        > > Hello Francois
        > > Thanks for the suggestion. I tried it but with no result. It seems that
        > > setting the CharSet to Unicode can include ansi but not the other way
        > > around
        > > and in this case it does not affect the calling procedure.
        > > Best Utaro
        > >
        > >
        > > -----Original Message-----
        > > From: swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
        > <mailto:swisseph%40yahoogroups.com>
        > [mailto:swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
        > <mailto:swisseph%40yahoogroups.com> ] On
        > Behalf
        > > Of Francois Rouleau
        > > Sent: Friday, May 11, 2012 7:55 PM
        > > To: swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
        > <mailto:swisseph%40yahoogroups.com>
        > > Subject: Re: [SWISSEPH] Re: Fwd: RE:calling swe_rise_trans()
        > >
        > > I wonder if using "CharSet = CharSet.Ansi" instead of "CharSet =
        > > CharSet.Unicode" in your attribute could solve your problem?
        > >
        > > Francois
        > >
        > > On Fri, May 11, 2012 at 8:42 PM, Utaro <utaro@...
        > <mailto:utaro%40astrotrader.com>
        > <mailto:utaro%40astrotrader.com> > wrote:
        > >
        > > > **
        > >
        > > >
        > > >
        > > > Yes, char and string are obviously different type but in C# or VBA
        what
        > > is
        > > > used in C as char* can be declared as string and works fine. If I
        > > remember
        > > > correctly, I first declared serr as char in C# then the compiler threw
        > an
        > > > exception. So then tried the string and it worked. A good example is
        > the
        > > > widely used swe_calc() function. The serr is declared as string in
        both
        > > VBA
        > > > or C# and it works.
        > > >
        > > > Once I get some kind of argument exception by able to call the dll at
        > > > least it is a good sign because it is a proof that C# is calling the
        > dll
        > > > function but right now I can't reach to that stage getting an error
        > > message
        > > > stating "unable to find entry point name _swe_rise_trans@52 in
        > > > swedll32.dll".
        > > >
        > > > My current logic is to check the source and if it proves to take too
        > long
        > > > to accomplish my project then I will work around by writing a library
        > > > looking for a conjunction or opposition of planetary bodies to the ASC
        > > and
        > > > MC
        > > >
        > > > Ty.
        > > >
        > > >
        > > > Utaro
        > > >
        > > > From: swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
        > <mailto:swisseph%40yahoogroups.com>
        > [mailto:swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
        > <mailto:swisseph%40yahoogroups.com> ] On
        > > > Behalf Of Alois Treindl
        > > > Sent: Friday, May 11, 2012 4:54 PM
        > > > To: swisseph@yahoogroups.com <mailto:swisseph%40yahoogroups.com>
        > <mailto:swisseph%40yahoogroups.com>
        > > > Subject: Re: [SWISSEPH] Re: Fwd: RE:calling swe_rise_trans()
        > > >
        > > >
        > > > I was wrong, had jumped to the next function when reading the docu.
        > > > *tret is a pointer to just one double.
        > > >
        > > > On 11.05.12 23:31, astropalaver wrote:
        > > > >
        > > > >
        > > > >
        > > > > I hope that "*tret" isn't really supposed to be an array of 20
        > doubles!
        > > > >
        > > > > I've been passing the address of a double and it seems to work just
        > > > fine. I can't imagine what the other doubles might hold! I'll have to
        > > check
        > > > the source code.
        > > > >
        > > > >> From the docs: 6.10.swe_rise_trans()
        > > > >
        > > > > double *tret, /* return address (double) for rise time etc. */
        > > > >
        > > > > Thanks for the wonderful dll!
        > > > >
        > > > > Jay
        > > >
        > > > [Non-text portions of this message have been removed]
        > > >
        > > >
        > > >
        > >
        > > [Non-text portions of this message have been removed]
        > >
        > > ------------------------------------
        > >
        > > Yahoo! Groups Links
        > >
        > >
        > >
        >
        > [Non-text portions of this message have been removed]
        >
        > ------------------------------------
        >
        > Yahoo! Groups Links
        >
        > [Non-text portions of this message have been removed]
        >
        > [Non-text portions of this message have been removed]
        >
        > [Non-text portions of this message have been removed]
        >
        >
        >


        [Non-text portions of this message have been removed]



        ------------------------------------

        Yahoo! Groups Links
      Your message has been successfully submitted and would be delivered to recipients shortly.