Module: Magvar

Defined in:
lib/magvar.rb,
lib/magvar/version.rb,
ext/magvar/magvar.c

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.variation_at(deg_lat, deg_lon, elev_km_msl, at_time) ⇒ Object

lat/lon

decimal radians (S and W are negative)

alt

altitude above sea level in km

jd

Julian date

Returns a two-element array, [var, dip] (radians)



563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
# File 'ext/magvar/magvar.c', line 563

static VALUE rb_magvar(VALUE self, VALUE deg_lat, VALUE deg_lon, VALUE elev_km_msl, VALUE at_time)
{
    int yy = FIX2INT(rb_funcall(at_time, rb_intern("year"), 0));
    // The year argument is not a full int but the decimal part (17 for 2017, 99 for 1999 etc)
    if (yy > 20) {
      yy -= 1900;
    } else {
      yy -= 2000;
    }
    int mm = FIX2INT(rb_funcall(at_time, rb_intern("month"), 0));
    int dd = FIX2INT(rb_funcall(at_time, rb_intern("day"), 0));
    unsigned long cjd = yymmdd_to_julian_days(yy, mm, dd);
    double mv_deg = calc_magvar(NUM2DBL(deg_lat), NUM2DBL(deg_lon), cjd, NUM2DBL(elev_km_msl));
    return rb_float_new(mv_deg);
}