Skip to content

Commit

Permalink
correct return type for swe_sol_eclipse_when_glob
Browse files Browse the repository at this point in the history
  • Loading branch information
awongh committed Jan 30, 2024
1 parent b3e495c commit 72d79a0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
24 changes: 9 additions & 15 deletions ext/swe4r/swe4r.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,14 +579,21 @@ static VALUE t_swe_sol_eclipse_when_glob(VALUE self, VALUE julian_ut, VALUE ifla
AS_BOOL backward = TRUE;
char serr[AS_MAXCH];

if (swe_sol_eclipse_when_glob(NUM2DBL(julian_ut), NUM2INT(iflag), NUM2INT(ifltype), tret, backward, serr) < 0)
int retval = 0;
retval = swe_sol_eclipse_when_glob(NUM2DBL(julian_ut), NUM2INT(iflag), NUM2INT(ifltype), tret, backward, serr);
if (retval == ERR)
rb_raise(rb_eRuntimeError, serr);
VALUE ret_num = INT2NUM(retval);

VALUE _tret = rb_ary_new();
for (int i = 0; i < 10; i++)
rb_ary_push(_tret, rb_float_new(tret[i]));

return _tret;
VALUE output = rb_ary_new();
rb_ary_push(output, ret_num);
rb_ary_push(output, _tret);

return output;
}

static VALUE t_swe_sol_eclipse_where(VALUE self, VALUE julian_ut, VALUE iflag)
Expand Down Expand Up @@ -743,28 +750,15 @@ void Init_swe4r()
// rb_define_module_function(rb_mSwe4r, "swe_helio_cross_ut", t_swe_helio_cross_ut, 4);

rb_define_module_function(rb_mSwe4r, "swe_pheno_ut", t_swe_pheno_ut, 3);

// swe_sol_eclipse_when_loc(tjd...) finds the next eclipse for a given geographic position;
rb_define_module_function(rb_mSwe4r, "swe_sol_eclipse_when_loc", t_swe_sol_eclipse_when_loc, 5);

// swe_sol_eclipse_when_glob(tjd...) finds the next eclipse globally;
rb_define_module_function(rb_mSwe4r, "swe_sol_eclipse_when_glob", t_swe_sol_eclipse_when_glob, 3);

// swe_sol_eclipse_where() computes the geographic location of a solar eclipse for a given tjd;
rb_define_module_function(rb_mSwe4r, "swe_sol_eclipse_where", t_swe_sol_eclipse_where, 2);

// swe_sol_eclipse_how() computes attributes of a solar eclipse for a given tjd, geographic longitude, latitude and height.
rb_define_module_function(rb_mSwe4r, "swe_sol_eclipse_how", t_swe_sol_eclipse_how, 5);

// Lunar eclipses:

// swe_lun_eclipse_when_loc(tjd...) finds the next lunar eclipse for a given geographic position;
rb_define_module_function(rb_mSwe4r, "swe_lun_eclipse_when_loc", t_swe_lun_eclipse_when_loc, 5);

// swe_lun_eclipse_when(tjd...) finds the next lunar eclipse;
rb_define_module_function(rb_mSwe4r, "swe_lun_eclipse_when", t_swe_lun_eclipse_when, 3);

// swe_lun_eclipse_how() computes the attributes of a lunar eclipse for a given tjd.
rb_define_module_function(rb_mSwe4r, "swe_lun_eclipse_how", t_swe_lun_eclipse_how, 5);

// Risings, settings, and meridian transits of planets and stars:
Expand Down
40 changes: 30 additions & 10 deletions test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,38 @@ def test_swe_sol_eclipse_when_loc
def test_swe_sol_eclipse_when_glob
result = Swe4r::swe_sol_eclipse_when_glob(2444838.972916667, Swe4r::SEFLG_MOSEPH, Swe4r::SE_ECL_TOTAL)
test_data = [
2444816.656780241,
2444816.649699564,
2444816.5496100746,
2444816.764137677,
2444816.5954617294,
2444816.7181679048,
2444816.595788629,
2444816.717870053,
0.0,
0.0
5,
[
2444816.656780241,
2444816.649699564,
2444816.5496100746,
2444816.764137677,
2444816.5954617294,
2444816.7181679048,
2444816.595788629,
2444816.717870053,
0.0,
0.0
]
]
assert_equal(test_data, result)

eclipse_type = result[0]
type_results = []

type_results << "SE_ECL_TOTAL" if (eclipse_type & Swe4r::SE_ECL_TOTAL) == Swe4r::SE_ECL_TOTAL
type_results << "SE_ECL_CENTRAL" if (eclipse_type & Swe4r::SE_ECL_CENTRAL) == Swe4r::SE_ECL_CENTRAL
type_results << "SE_ECL_NONCENTRAL" if (eclipse_type & Swe4r::SE_ECL_NONCENTRAL) == Swe4r::SE_ECL_NONCENTRAL
type_results << "SE_ECL_ANNULAR" if (eclipse_type & Swe4r::SE_ECL_ANNULAR) == Swe4r::SE_ECL_ANNULAR
type_results << "SE_ECL_PARTIAL" if (eclipse_type & Swe4r::SE_ECL_PARTIAL) == Swe4r::SE_ECL_PARTIAL
type_results << "SE_ECL_ANNULAR_TOTAL" if (eclipse_type & Swe4r::SE_ECL_ANNULAR_TOTAL) == Swe4r::SE_ECL_ANNULAR_TOTAL

expected_type_results = [
"SE_ECL_TOTAL",
"SE_ECL_CENTRAL"
]

assert_equal(expected_type_results, type_results)
end

# swe_sol_eclipse_where() computes the geographic location of a solar eclipse for a given tjd;
Expand Down

0 comments on commit 72d79a0

Please sign in to comment.