mivion / swisseph

Swiss Ephemeris binding for node.js
GNU General Public License v2.0
196 stars 72 forks source link

swe_rise_trans Inaccuracy #10

Closed blissGitHub closed 8 years ago

blissGitHub commented 8 years ago

Hi, The C version's result for swe_rise_trans for the same input and the Javascript Wrapper version's result for swe_rise_trans is off by 2 minutes.

Here is an actual example. In C to calculate the sunrise of the julian day = 2444663.309024 one would use this:

    double geopos1[3] = {121.133333, 14.550000};
    double sunriseBeforeBirth1[10];

    swe_rise_trans(2444663.309024, //julian date
                   SE_SUN, //planet num
                   starname, //starname
                   2, // 2
                   SE_CALC_RISE, //SE_CALC_RISE OR SE_CALC_SET
                   geopos1, //geopos
                   1013.25, //1013.25
                   10, //10
                   sunriseBeforeBirth1, //return value
                   serr); //serr

The result of this is in sunriseBeforeBirth1[0] and the value is 2444663.425763

In Javascript for the same julian day 2444663.309024 with the same input:

swisseph.swe_rise_trans(
                    2444663.309024,//julday_ut - 1,
                    swisseph.SE_SUN,//
                    '',//starname
                    swisseph.SEFLG_MOSEPH,
                    swisseph.SE_CALC_RISE,  //rsmi
                    121.133333, //longitude
                    14.550000, //latitude
                    1013.25,  //height
                    10,  //atpress=0.0
                    26,//attemp
                    function(result){
                      console.log('xxx');
                      console.log(result);
                    });

The result gives: { name: '', transitTime: 2444663.4275476774 }

In summary, the first line below is the result of swe_rise_trans from C and the second line is from Javascript for the same inputs(parameters). 2444663.425763 2444663.4275476774 From above, the third decimal place number is different and it is causing a 2 minute difference.

What's the reason for this? Can this be fixed? I would have expected it to have the same result since it is essentially the same API.... Thank you...

mivion commented 8 years ago

Hi,

Thanks for the report. Maybe the problem in calc flags (SEFLG_MOSEPH)?

blissGitHub commented 8 years ago

Hi,

I've tried it with SEFLG_SWIEPH and SEFLG_JPLEPH too and those give the same Julian Number which is 2 minutes off when converted to UTC.....

Do you think this is something that can be fixed?

I hope it can be...

Thank you...

afucher commented 8 years ago

I think that can be a problem with float numbers in javascript... Something like:

0.1+0.2 0.30000000000000004

gordalina commented 8 years ago

Are you using the ephemeris files in both programs? If you set the flag SEFLG_SWIEPH, you still need the epehemeris.

blissGitHub commented 8 years ago

Hi,

Yes I am using all of the ephemeris files for both SEFLG_SWIEPH and SEFLG_JPLEPH....

The difference in the C version and Javascript version is: 2444663.425763 vs 2444663.4275476774

Starting from the 3rd decimal place the difference already shows....

mivion commented 8 years ago

This too big error, it should't be because of javacript. I'll test this case later. Any one else see this error?

mivion commented 8 years ago

Hi,

There is error in your code when you call swisseph from C version. geopos1 must contains 3 values: lon, lan, height. and the next argument is atpress not height. Full syntax is:

int32 swe_rise_trans(
  double tjd_ut,
  int32 ipl,
  char *starname,
  int32 epheflag,
  int32 rsmi,
  double *geopos, /* in [3] */
  double atpress,
  double attemp,
  double *tret, /* out [1] */
  char *serr /* out [AS_MAXCH] */
)
blissGitHub commented 8 years ago

Hi, Ok, I've made the necessary changes. this is the new C version:

double geopos1[3] = {121.133333, 14.550000,1013.25}; double sunriseBeforeBirth1[10];

swe_rise_trans(2444663.309024, //julian date
               SE_SUN, //planet num
               starname, //starname
               SEFLG_MOSEPH,// was 2
               SE_CALC_RISE, //SE_CALC_RISE OR SE_CALC_SET
               geopos1, //geopos
               10,//was 1013.25,
               26, //10
               sunriseBeforeBirth1, //return value
               serr); //serr

This is the output: 2444663.427548

Now this is the Javascript result: 2444663.4275476774

and this is the C result: 2444663.427548

Smaller difference.

Thank you very much and sorry for the false alarm....

mivion commented 8 years ago

Hi,

There is no difference, because of printf in C version makes round by default. Try to use:

printf("%.10f", sunriseBeforeBirth1[0]);

You'll see exact the save value.

blissGitHub commented 8 years ago

Hi, Ok....just tried it..yes you are right... Thank you very much....

ajithkumar666 commented 7 years ago

swe_rise_trans is not working for swift