Class: CalcSun

Inherits:
Object
  • Object
show all
Defined in:
lib/calc_sun/version.rb,
ext/calc_sun/calc_sun.c

Overview

class file CalcSun

Constant Summary collapse

VERSION =

VERSION = ‘1.2.10’

'1.2.10'.freeze

Instance Method Summary collapse

Constructor Details

#initializeObject

Create CalcSun class instance Ruby object.



36
37
38
# File 'ext/calc_sun/calc_sun.c', line 36

static VALUE t_init(VALUE self){
  return self;
}

Instance Method Details

#ajd(date) ⇒ Object

given Date or DateTime object convert to Astronomical Julian Day Number.



79
80
81
82
# File 'ext/calc_sun/calc_sun.c', line 79

static VALUE func_get_ajd(VALUE self, VALUE vdatetime){
  double ajd = NUM2DBL(rb_funcall(vdatetime, rb_intern("ajd"), 0));
  return DBL2NUM(ajd);
}

#ajd2dt(ajd) ⇒ Object

give Astronomical Julian Day Number convert to DateTime object.



64
65
66
67
68
69
70
# File 'ext/calc_sun/calc_sun.c', line 64

static VALUE func_ajd_2_datetime(VALUE self, VALUE vajd){
  VALUE cDateTime = rb_const_get(rb_cObject, rb_intern("DateTime"));
  double ajd = NUM2DBL(vajd) + 0.5;
  VALUE vfajd = DBL2NUM(ajd);
  VALUE vdatetime = rb_funcall(cDateTime, rb_intern("jd"), 1, vfajd);
  return vdatetime;
}

#altitude(ajd, lat, lon) ⇒ Object

given an Astronomical Julian Day Number and local Latitude and Longitude, returns the Altitude of the Sun in degrees. rounded to 12 decimal places.



862
863
864
865
866
867
868
869
870
# File 'ext/calc_sun/calc_sun.c', line 862

static VALUE func_altitude(VALUE self, VALUE vajd, VALUE vlat, VALUE vlon){
  double lat = NUM2DBL(vlat) * D2R;
  double delta = NUM2DBL(func_declination(self, vajd)) * D2R;
  double lha = NUM2DBL(func_lha(self, vajd, vlon)) * D2R;
  double alt =
  asin(sin(lat) * sin(delta) +
    cos(lat) * cos(delta) * cos(lha)) * R2D;
  return DBL2NUM(roundf(alt * RND12) / RND12);
}

#azimuth(ajd, lat, lon) ⇒ Object

given an Astronomical Julian Day Number and local Latitude and Longitude, returns the Azimuth of the Sun in degrees. rounded to 12 decimal places.



881
882
883
884
885
886
887
888
889
890
# File 'ext/calc_sun/calc_sun.c', line 881

static VALUE func_azimuth(VALUE self, VALUE vajd, VALUE vlat, VALUE vlon){
  double lat = NUM2DBL(vlat) * D2R;
  double delta = NUM2DBL(func_declination(self, vajd)) * D2R;
  double lha = NUM2DBL(func_lha(self, vajd, vlon)) * D2R;
  double az;
  az =
  atan2(sin(lha), cos(lha) * sin(lat) -
            tan(delta) * cos(lat)) * R2D + 180.0;
  return DBL2NUM(roundf(az * RND12) / RND12);
}

#daylight_time(ajd, lat) ⇒ Object

given an Astronomical Julian Day Number and local Latitude, returns Hours of Day Light. rounded to 12 decimal places.



545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'ext/calc_sun/calc_sun.c', line 545

static VALUE func_dlt(VALUE self, VALUE vajd, VALUE vlat){
  double jd = floor(NUM2DBL(vajd));
  double vsin_alt = sin(-0.8333 * D2R);
  double vlat_r = NUM2DBL(vlat) * D2R;
  double vcos_lat = cos(vlat_r);
  double vsin_lat = sin(vlat_r);
  VALUE vjd = DBL2NUM(jd);
  double vooe =
  NUM2DBL(func_obliquity_of_ecliptic(self, vjd));
  double vtl =
  NUM2DBL(func_true_longitude(self, vjd));
  double vsin_dec = sin(vooe) * sin(vtl);
  double vcos_dec =
  sqrt( 1.0 - vsin_dec * vsin_dec );
  double vdl =
  acos(
    (vsin_alt - vsin_dec * vsin_lat) /
    (vcos_dec * vcos_lat));
  double vdla = vdl * R2D;
  double vdlt = vdla / 15.0 * 2.0;
  return DBL2NUM(roundf(vdlt * RND12) / RND12);
}

#declination(ajd) ⇒ Object

given an Astronomical Julian Day Number returns Declination of Sun in degrees. rounded to 12 decimal places.



508
509
510
511
512
513
514
515
516
517
518
519
# File 'ext/calc_sun/calc_sun.c', line 508

static VALUE func_declination(VALUE self, VALUE vajd){
  double vex =
  NUM2DBL(func_ecliptic_x(self, vajd));
  double vey =
  NUM2DBL(func_ecliptic_y(self, vajd));
  double vooe =
  NUM2DBL(func_obliquity_of_ecliptic(self, vajd));
  double ver = sqrt(vex * vex + vey * vey);
  double vz = vey * sin(vooe);
  double vdec = atan2(vz, ver);
  return DBL2NUM(roundf((vdec * R2D) * RND12) / RND12);
}

#diurnal_arc(ajd, lat) ⇒ Object

given an Astronomical Julian Day Number and local Latitude, returns Hours from Noon or half Day Light Time. rounded to 12 decimal places.



577
578
579
580
581
582
# File 'ext/calc_sun/calc_sun.c', line 577

static VALUE func_diurnal_arc(VALUE self, VALUE vajd, VALUE vlat){
  double jd = floor(NUM2DBL(vajd));
  double dlt = NUM2DBL(func_dlt(self, DBL2NUM(jd), vlat));
  double da = dlt / 2.0;
  return DBL2NUM(roundf(da * RND12) / RND12);
}

#eccentric_anomaly(ajd) ⇒ Object

given an Astronomical Julian Day Number returns Eccentric Anomaly of Sun in radians. rounded to 12 decimal places.



208
209
210
211
212
213
214
215
216
# File 'ext/calc_sun/calc_sun.c', line 208

static VALUE func_eccentric_anomaly(VALUE self, VALUE vajd){
  double ve =
  NUM2DBL(func_eccentricity(self, vajd));
  double vml =
  NUM2DBL(func_mean_longitude(self, vajd));
  double vea =
  vml + ve * sin(vml) * (1.0 + ve * cos(vml));
  return DBL2NUM(roundf(vea * RND12) / RND12);
}

#eccentricity(ajd) ⇒ Object

given an Astronomical Julian Day Number returns Eccentriciy of Earth Orbit around Sun. rounded to 12 decimal places.



125
126
127
128
129
130
131
132
# File 'ext/calc_sun/calc_sun.c', line 125

static VALUE func_eccentricity(VALUE self, VALUE vajd){
  double jd = NUM2DBL(vajd);
  double d = jd - DJ00;
  double ve =
  0.016709 -
  1.151e-9 * d;
  return DBL2NUM(roundf(ve * RND12) / RND12);
}

#ecliptic_x(ajd) ⇒ Object

given an Astronomical Julian Day Number returns ecliptic x component. rounded to 12 decimal places.



437
438
439
440
441
442
443
444
# File 'ext/calc_sun/calc_sun.c', line 437

static VALUE func_ecliptic_x(VALUE self, VALUE vajd){
  double vrv =
  NUM2DBL(func_rv(self, vajd));
  double vtl =
  NUM2DBL(func_true_longitude(self, vajd));
  double vex = vrv * cos(vtl);
  return DBL2NUM(roundf(vex * RND12) / RND12);
}

#ecliptic_y(ajd) ⇒ Object

given an Astronomical Julian Day Number returns ecliptic y component. rounded to 12 decimal places.



454
455
456
457
458
459
460
461
# File 'ext/calc_sun/calc_sun.c', line 454

static VALUE func_ecliptic_y(VALUE self, VALUE vajd){
  double vrv =
  NUM2DBL(func_rv(self, vajd));
  double vtl =
  NUM2DBL(func_true_longitude(self, vajd));
  double vey = vrv * sin(vtl);
  return DBL2NUM(roundf(vey * RND12) / RND12);
}

#eot(ajd) ⇒ Object

given an Astronomical Julian Day Number returns equation of time in degrees rounded to 12 decimal places.



796
797
798
799
800
801
802
803
804
805
806
# File 'ext/calc_sun/calc_sun.c', line 796

static VALUE func_eot(VALUE self, VALUE vajd){
  double ma =
  NUM2DBL(func_mean_anomaly(self, vajd));
  double ta =
  NUM2DBL(func_true_anomaly(self, vajd));
  double tl =
  NUM2DBL(func_true_longitude(self, vajd));
  double ra = 15.0 * D2R *
  NUM2DBL(func_right_ascension(self, vajd));
  return DBL2NUM(roundf(anp(ma - ta + tl - ra) * R2D * RND12) / RND12 );
}

#eot_jd(ajd) ⇒ Object

given an Astronomical Julian Day Number returns equation of time as time of a fractional day for easy Julian Number work rounded to 12 decimal places.



817
818
819
820
821
822
# File 'ext/calc_sun/calc_sun.c', line 817

static VALUE func_eot_jd(VALUE self, VALUE vajd){
  double veot =
  NUM2DBL(func_eot(self, vajd));
  double jdeot = veot / 360.0;
  return DBL2NUM(roundf(jdeot * RND12) / RND12);
}

#eot_min(ajd) ⇒ Object

given an Astronomical Julian Day Number returns equation of time in minutes rounded to 12 decimal places.



832
833
834
835
# File 'ext/calc_sun/calc_sun.c', line 832

static VALUE func_eot_min(VALUE self, VALUE vajd){
  double eot = NUM2DBL(func_eot(self, vajd));
  return DBL2NUM(roundf((eot / 15 * 60) * RND12) / RND12);
}

#equation_of_center(ajd) ⇒ Object

given an Astronomical Julian Day Number returns Equation of Center in radians. rounded to 12 decimal places.



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'ext/calc_sun/calc_sun.c', line 144

static VALUE func_equation_of_center(VALUE self, VALUE vajd){
  double mas =
  NUM2DBL(func_mean_anomaly(self, vajd));
  double eoe =
  NUM2DBL(func_eccentricity(self, vajd));
  double sin1a = sin(1.0 * mas) * 1.0 / 4.0;
  double sin1b = sin(1.0 * mas) * 5.0 / 96.0;
  double sin2a = sin(2.0 * mas) * 11.0 / 24.0;
  double sin2b = sin(2.0 * mas) * 5.0 / 4.0;
  double sin3a = sin(3.0 * mas) * 13.0 / 12.0;
  double sin3b = sin(3.0 * mas) * 43.0 / 64.0;
  double sin4 = sin(4.0 * mas) * 103.0 / 96.0;
  double sin5 = sin(5.0 * mas) * 1097.0 / 960.0;
  double ad3 = sin3a - sin1a;
  double ad4 = sin4 - sin2a;
  double ad5 = sin5 + sin1b - sin3b;
  double veoc = eoe * (sin1a * 8.0 + eoe * (sin2b + eoe * (ad3 + eoe * (ad4 + eoe * ad5))));
  return DBL2NUM(roundf(veoc * RND12) / RND12);
}

#gha(ajd) ⇒ Object

given an Astronomical Julian Day Number returns Greenwich Hour Angle in degrees. rounded to 12 decimal places.



491
492
493
494
495
496
497
498
# File 'ext/calc_sun/calc_sun.c', line 491

static VALUE func_gha(VALUE self, VALUE vajd){
  double gmsa =
  NUM2DBL(func_mean_sidetime(self, vajd)) * 15 * D2R;
  double ra =
  NUM2DBL(func_right_ascension(self, vajd)) * 15 * D2R;
  double gha = anp(gmsa - ra);
  return DBL2NUM(roundf(gha * R2D * RND12) / RND12);
}

#gmsa(ajd) ⇒ Object

given an Astronomical Julian Day Number returns Greenwich Mean Sidereal Time as angle. rounded to 12 decimal places.



375
376
377
378
379
380
381
382
# File 'ext/calc_sun/calc_sun.c', line 375

static VALUE func_gmsa(VALUE self, VALUE vajd){
  double ajd = NUM2DBL(vajd) - 0.5;
  double ajdt = fmod(ajd, 1.0);
  double vtr = ajdt * 24.0 * 1.00273790935 * 15 * D2R;
  double msar0 = NUM2DBL(func_gmsa0(self, vajd)) * D2R;
  double msa = anp(msar0 + vtr) * R2D;
  return DBL2NUM(roundf(msa * RND12) / RND12);
}

#gmsa0(ajd) ⇒ Object

given an Astronomical Julian Day Number returns Greenwich Mean Sidereal Time at midnight as angle. rounded to 12 decimal places.



351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'ext/calc_sun/calc_sun.c', line 351

static VALUE func_gmsa0(VALUE self, VALUE vajd){
  double msa0;
  double ajd0 = NUM2DBL(vajd);
  double ajdt = fmod(ajd0, 1.0);
  if (ajdt <= 0.5){
    ajd0 -= 0.5;
    ajd0 = floor(ajd0) + 0.5;
  }
  else{
    ajd0 = floor(ajd0) + 0.5;
  }
  msa0 =
  NUM2DBL(func_mean_sidetime(self, DBL2NUM(ajd0))) * 15;
  return DBL2NUM(roundf(msa0 * RND12) / RND12);
}

#gmst(ajd) ⇒ Object

given an Astronomical Julian Day Number returns Greenwich Mean Sidereal Time in hours. rounded to 12 decimal places.



406
407
408
409
# File 'ext/calc_sun/calc_sun.c', line 406

static VALUE func_gmst(VALUE self, VALUE vajd){
  double vmst = NUM2DBL(func_gmsa(self, vajd)) / 15.0;
  return DBL2NUM(roundf(vmst * RND12) / RND12);
}

#gmst0(ajd) ⇒ Object

given an Astronomical Julian Day Number returns Greenwich Mean Sidereal Time at midnight in hours. rounded to 12 decimal places.



392
393
394
395
396
# File 'ext/calc_sun/calc_sun.c', line 392

static VALUE func_gmst0(VALUE self, VALUE vajd){
  double era0 =
  NUM2DBL(func_gmsa0(self, vajd)) / 15.0;
  return DBL2NUM(roundf(era0 * RND12) / RND12);
}

#jd(date) ⇒ Object

given Date or DateTime object convert to JD number.



91
92
93
94
# File 'ext/calc_sun/calc_sun.c', line 91

static VALUE func_get_jd(VALUE self, VALUE vdatetime){
  double jd = NUM2DBL(rb_funcall(vdatetime, rb_intern("jd"), 0));
  return DBL2NUM(jd);
}

#jd2000_dif(ajd) ⇒ Object

given an Astronomical Julian Day Number returns the number of days and decimal time since JD 2000.



765
766
767
768
769
# File 'ext/calc_sun/calc_sun.c', line 765

static VALUE func_jd_from_2000(VALUE self, VALUE vajd){
  double ajd = NUM2DBL(vajd);
  double days = ajd - 2451545.0;
  return INT2NUM(days);
}

#jd2000_dif_lon(ajd, lon) ⇒ Object

given an Astronomical Julian Day Number and local Longitude, returns the number of days and decimal time since JD 2000. rounded to 12 decimal places.



781
782
783
784
785
786
# File 'ext/calc_sun/calc_sun.c', line 781

static VALUE func_days_from_2000(VALUE self, VALUE vajd, VALUE vlon){
  double jd = NUM2DBL(vajd);
  double lon = NUM2DBL(vlon);
  double days = jd - DJ00 - lon / 360;
  return DBL2NUM(roundf(days * RND12) / RND12);
}

#lha(ajd, lon) ⇒ Object

given an Astronomical Julian Day Number and local Longitude, returns Local Hour Angle in degrees. rounded to 12 decimal places.



846
847
848
849
850
851
# File 'ext/calc_sun/calc_sun.c', line 846

static VALUE func_lha(VALUE self, VALUE vajd, VALUE vlon){
  double lon = NUM2DBL(vlon) * D2R;
  double gha = NUM2DBL(func_gha(self, vajd)) * D2R;
  double lha = anp(gha + lon) * R2D;
  return DBL2NUM(roundf(lha * RND12) / RND12);
}

#local_sidereal_time(ajd, lon) ⇒ Object

given an Astronomical Julian Day Number and local Longitude, returns Local Mean Sidereal Time in hours. rounded to 12 decimal places.



530
531
532
533
534
# File 'ext/calc_sun/calc_sun.c', line 530

static VALUE func_local_sidetime(VALUE self, VALUE vajd, VALUE vlon){
  double vst = NUM2DBL(func_mean_sidetime(self, vajd));
  double vlst = vst + NUM2DBL(vlon) / 15.0 ;
  return DBL2NUM(fmod(roundf(vlst * RND12) / RND12, 24.0));
}

#longitude_of_perihelion(ajd) ⇒ Object

given an Astronomical Julian Day Number returns Longitude of Sun at Perihelion in radians. rounded to 12 decimal places.



243
244
245
246
247
248
# File 'ext/calc_sun/calc_sun.c', line 243

static VALUE func_longitude_of_perihelion(VALUE self, VALUE vajd){
  double vml = NUM2DBL(func_mean_longitude(self, vajd));
  double vma = NUM2DBL(func_mean_anomaly(self, vajd));
  double vlop = anp(vml - vma);
  return DBL2NUM(roundf(vlop * RND12) / RND12);
}

#mean_anomaly(ajd) ⇒ Object

given an Astronomical Julian Day Number returns Mean Anomaly of Sun in radians rounded to 12 decimal places.



105
106
107
108
109
110
111
112
113
114
115
# File 'ext/calc_sun/calc_sun.c', line 105

static VALUE func_mean_anomaly(VALUE self, VALUE vajd){
  double ajd = NUM2DBL(vajd);
  double t = (ajd - DJ00) / 36525;
  double vma =
  fmod((              357.52910918     +
    t * (           35999.05029113889  +
    t * (     1.0 / -6507.592190889371 +
    t * (  1.0 / 26470588.235294115    +
    t * (1.0 / -313315926.8929504))))) * D2R, M2PI);
  return DBL2NUM(roundf(vma * RND12) / RND12);
}

#mean_longitude(ajd) ⇒ Object

given an Astronomical Julian Day Number returns Mean Longitude of Sun in radians. rounded to 12 decimal places.



189
190
191
192
193
194
195
196
197
198
# File 'ext/calc_sun/calc_sun.c', line 189

static VALUE func_mean_longitude(VALUE self, VALUE vajd){
  double jd = NUM2DBL(vajd);
  double d = jd - DJ00;
  double vml =
  fmod(
    (280.4664567 +
     0.9856473601037645 * d
    ) * D2R, M2PI);
  return DBL2NUM(roundf(vml * RND12) / RND12);
}

#mean_sidereal_time(ajd) ⇒ Object

given an Astronomical Julian Day Number returns Greenwich Mean Sidereal Time in hours. rounded to 12 decimal places.



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'ext/calc_sun/calc_sun.c', line 327

static VALUE func_mean_sidetime(VALUE self, VALUE vajd){
  double ajd = NUM2DBL(vajd);
  long double sidereal;
  long double t;
  t = (ajd - 2451545.0) / 36525.0;
  /* calc mean angle */
  sidereal =
  280.46061837 +
  (360.98564736629 * (ajd - 2451545.0)) +
  (0.000387933 * t * t) -
  (t * t * t / 38710000.0);
  sidereal = anp(sidereal * D2R) * R2D;
  /* change to hours */
  return DBL2NUM(fmod(roundf((sidereal / 15.0) * RND12) / RND12, 24.0));
}

#noon(ajd, lat, lon) ⇒ Object

given an Astronomical Julian Day Number and local Latitude and Longitude, returns a Ruby DateTime object when Sun transits local meridian.



686
687
688
689
690
691
692
# File 'ext/calc_sun/calc_sun.c', line 686

static VALUE func_noon(VALUE self, VALUE vajd, VALUE vlat, VALUE vlon){
  double nt = NUM2DBL(func_t_south(self, vajd, vlon));
  double ajd = NUM2DBL(vajd);
  double ntajd = floor(ajd) - 0.5 + nt / 24.0;
  VALUE vnt = DBL2NUM(ntajd);
  return func_ajd_2_datetime(self, vnt);
}

#noon_az(ajd, lat, lon) ⇒ Object

given an Astronomical Julian Day Number and local Latitude and Longitude, returns the Azimuth of the Sun at transit in degrees. Note : should be very close to 180 degrees.



915
916
917
918
919
# File 'ext/calc_sun/calc_sun.c', line 915

static VALUE func_noon_az(VALUE self, VALUE vajd, VALUE vlat, VALUE vlon){
  double njd = NUM2DBL(func_noon_jd(self, vajd, vlat, vlon));
  double naz = NUM2DBL(func_azimuth(self, DBL2NUM(njd), vlat, vlon));
  return DBL2NUM(naz);
}

#noon_jd(ajd, lat, lon) ⇒ Object

given an Astronomical Julian Day Number and local Latitude and Longitude, returns a Astronomical Julian Day Number when Sun transits local meridian.



703
704
705
706
707
708
# File 'ext/calc_sun/calc_sun.c', line 703

static VALUE func_noon_jd(VALUE self, VALUE vajd, VALUE vlat, VALUE vlon){
  double nt = NUM2DBL(func_t_south(self, vajd, vlon));
  double ajd = NUM2DBL(vajd);
  double ntajd = floor(ajd) - 0.5 + nt / 24.0;
  return DBL2NUM(ntajd);
}

#obliquity_of_ecliptic(ajd) ⇒ Object

given an Astronomical Julian Day Number returns Earth Tilt (Obliquity) in radians. rounded to 12 decimal places.



226
227
228
229
230
231
232
# File 'ext/calc_sun/calc_sun.c', line 226

static VALUE func_obliquity_of_ecliptic(VALUE self, VALUE vajd){
  double jd = NUM2DBL(vajd);
  double d = jd - DJ00;
  double vooe =
  (23.439291 - 3.563E-7 * d) * D2R;
  return DBL2NUM(roundf(vooe * RND12) / RND12);
}

#radius_vector(ajd) ⇒ Object

given an Astronomical Julian Day Number returns radius vector. rounded to 12 decimal places.



419
420
421
422
423
424
425
426
427
# File 'ext/calc_sun/calc_sun.c', line 419

static VALUE func_rv(VALUE self, VALUE vajd){
  double vxv =
  NUM2DBL(func_xv(self, vajd));
  double vyv =
  NUM2DBL(func_yv(self, vajd));
  double vrv =
  sqrt(vxv * vxv + vyv * vyv);
  return DBL2NUM(roundf(vrv * RND12) / RND12);
}

#right_ascension(ajd) ⇒ Object

given an Astronomical Julian Day Number returns Right Ascension of Sun in hours. rounded to 12 decimal places.



471
472
473
474
475
476
477
478
479
480
481
# File 'ext/calc_sun/calc_sun.c', line 471

static VALUE func_right_ascension(VALUE self, VALUE vajd){
  double vey =
  NUM2DBL(func_ecliptic_y(self, vajd));
  double vooe =
  NUM2DBL(func_obliquity_of_ecliptic(self, vajd));
  double vex =
  NUM2DBL(func_ecliptic_x(self, vajd));
  double vra =
  fmod(atan2(vey * cos(vooe), vex) + M2PI, M2PI);
  return DBL2NUM(fmod(roundf((vra * R2D / 15.0) * RND12) / RND12, 24.0));
}

#rise(ajd.lat, lon) ⇒ Object

given an Astronomical Julian Day Number and local Latitude and Longitude, returns a Ruby DateTime object when Sun rises.



654
655
656
657
658
659
660
# File 'ext/calc_sun/calc_sun.c', line 654

static VALUE func_rise(VALUE self, VALUE vajd, VALUE vlat, VALUE vlon){
  double rt = NUM2DBL(func_t_rise(self, vajd, vlat, vlon));
  double ajd = NUM2DBL(vajd);
  double rtajd = floor(ajd) - 0.5 + rt / 24.0;
  VALUE vrt = DBL2NUM(rtajd);
  return func_ajd_2_datetime(self, vrt);
}

#rise_az(ajd, lat, lon) ⇒ Object

given an Astronomical Julian Day Number and local Latitude and Longitude, returns the Azimuth of the Sun rise in degrees.



900
901
902
903
904
# File 'ext/calc_sun/calc_sun.c', line 900

static VALUE func_rise_az(VALUE self, VALUE vajd, VALUE vlat, VALUE vlon){
  double rjd = NUM2DBL(func_rise_jd(self, vajd, vlat, vlon));
  double raz = NUM2DBL(func_azimuth(self, DBL2NUM(rjd), vlat, vlon));
  return DBL2NUM(raz);
}

#rise_jd(ajd, lat, lon) ⇒ Object

given an Astronomical Julian Day Number and local Latitude and Longitude, returns a Astronomical Julian Day Number when Sun rises.



670
671
672
673
674
675
# File 'ext/calc_sun/calc_sun.c', line 670

static VALUE func_rise_jd(VALUE self, VALUE vajd, VALUE vlat, VALUE vlon){
  double rt = NUM2DBL(func_t_rise(self, vajd, vlat, vlon));
  double ajd = NUM2DBL(vajd);
  double rtajd = floor(ajd) - 0.5 + rt / 24.0;
  return DBL2NUM(rtajd);
}

#set(ajd, lat, lon) ⇒ Object

given an Astronomical Julian Day Number and local Latitude and Longitude, returns a Ruby DateTime object when Sun sets.



718
719
720
721
722
723
724
725
726
727
728
729
730
# File 'ext/calc_sun/calc_sun.c', line 718

static VALUE func_set(VALUE self, VALUE vajd, VALUE vlat, VALUE vlon){
  VALUE vst;
  double stajd;
  double st = NUM2DBL(func_t_set(self, vajd, vlat, vlon));
  double nt = NUM2DBL(func_t_mid_day(self, vajd, vlat, vlon));
  double ajd = NUM2DBL(vajd);
  if (st < nt){
    st += 24.0;
  }
  stajd = floor(ajd) - 0.5 + st / 24.0;
  vst = DBL2NUM(stajd);
  return func_ajd_2_datetime(self, vst);
}

#set_az(ajd, lat, lon) ⇒ Object

given an Astronomical Julian Day Number and local Latitude and Longitude, returns the Azimuth of the Sun set in degrees.



929
930
931
932
933
# File 'ext/calc_sun/calc_sun.c', line 929

static VALUE func_set_az(VALUE self, VALUE vajd, VALUE vlat, VALUE vlon){
  double sjd = NUM2DBL(func_set_jd(self, vajd, vlat, vlon));
  double saz = NUM2DBL(func_azimuth(self, DBL2NUM(sjd), vlat, vlon));
  return DBL2NUM(saz);
}

#set_datetime('yyyy-mm-ddT00: 00:00+/-zoneoffset') ⇒ Object

or

set_datetime('20010203T040506+0700')

or

set_datetime('3rd Feb 2001 04:05:06 PM')

given a string representing date time convert to DateTime object.



51
52
53
54
55
# File 'ext/calc_sun/calc_sun.c', line 51

static VALUE func_set_datetime(VALUE self, VALUE vdatetime){
  VALUE cDateTime = rb_const_get(rb_cObject, rb_intern("DateTime"));
  VALUE vdate = rb_funcall(cDateTime, rb_intern("parse"), 1, vdatetime);
  return vdate;
}

#set_jd(ajd, lat, lon) ⇒ Object

given an Astronomical Julian Day Number and local Latitude and Longitude, returns a Astronomical Julian Day Number when Sun sets.



740
741
742
743
744
745
746
747
748
749
750
# File 'ext/calc_sun/calc_sun.c', line 740

static VALUE func_set_jd(VALUE self, VALUE vajd, VALUE vlat, VALUE vlon){
  double stajd;
  double st = NUM2DBL(func_t_set(self, vajd, vlat, vlon));
  double nt = NUM2DBL(func_t_mid_day(self, vajd, vlat, vlon));
  double ajd = NUM2DBL(vajd);
  if (st < nt){
    st += 24.0;
  }
  stajd = floor(ajd) - 0.5 + st / 24.0;
  return DBL2NUM(stajd);
}

#t_mid_day(ajd, lat, lon) ⇒ Object

given an Astronomical Julian Day Number and local Latitude and Longitude, returns Time in Hours when Sun transits local meridian. rounded to 12 decimal places.



626
627
628
629
# File 'ext/calc_sun/calc_sun.c', line 626

static VALUE func_t_mid_day(VALUE self, VALUE vajd, VALUE vlat, VALUE vlon){
  double ts = NUM2DBL(func_t_south(self, vajd, vlon));
  return DBL2NUM(fmod(roundf(ts * RND12) / RND12, 24.0));
}

#t_rise(ajd, lat, lon) ⇒ Object

given an Astronomical Julian Day Number and local Latitude and Longitude, returns Time in Hours when Sun rises. rounded to 12 decimal places.



611
612
613
614
615
# File 'ext/calc_sun/calc_sun.c', line 611

static VALUE func_t_rise(VALUE self, VALUE vajd, VALUE vlat, VALUE vlon){
  double ts = NUM2DBL(func_t_south(self, vajd, vlon));
  double da = NUM2DBL(func_diurnal_arc(self, vajd, vlat));
  return DBL2NUM(fmod(roundf((ts - da) * RND12) / RND12, 24.0));
}

#t_set(ajd, lat, lon) ⇒ Object

given an Astronomical Julian Day Number and local Latitude and Longitude, returns Time in Hours when Sun sets. rounded to 12 decimal places.



640
641
642
643
644
# File 'ext/calc_sun/calc_sun.c', line 640

static VALUE func_t_set(VALUE self, VALUE vajd, VALUE vlat, VALUE vlon){
  double ts = NUM2DBL(func_t_south(self, vajd, vlon));
  double da = NUM2DBL(func_diurnal_arc(self, vajd, vlat));
  return DBL2NUM(roundf(fmod((ts + da), 24.0) * RND12) / RND12);
}

#t_south(ajd, lon) ⇒ Object

given an Astronomical Julian Day Number and local Longitude, returns Time in Hours when Sun transits local meridian. rounded to 12 decimal places.



593
594
595
596
597
598
599
600
# File 'ext/calc_sun/calc_sun.c', line 593

static VALUE func_t_south(VALUE self, VALUE vajd, VALUE vlon){
  double jd = floor(NUM2DBL(vajd));
  double lst = NUM2DBL(func_local_sidetime(self, DBL2NUM(jd), vlon));
  double ra = NUM2DBL(func_right_ascension(self, DBL2NUM(jd)));
  double vx = lst - ra;
  double vt = vx - 24.0 * floor(vx * INV24 + 0.5);
  return DBL2NUM(fmod(roundf((12.0 - vt) * RND12) / RND12, 24.0));
}

#true_anomaly(ajd) ⇒ Object

given an Astronomical Julian Day Number returns True Anomaly of Sun in radians. rounded to 12 decimal places.



172
173
174
175
176
177
178
179
# File 'ext/calc_sun/calc_sun.c', line 172

static VALUE func_true_anomaly(VALUE self, VALUE vajd){
  double vma =
  NUM2DBL(func_mean_anomaly(self, vajd));
  double veoc =
  NUM2DBL(func_equation_of_center(self, vajd));
  double vta = vma + veoc;
  return DBL2NUM(roundf(vta * RND12) / RND12);
}

#true_anomaly1(ajd) ⇒ Object

given an Astronomical Julian Day Number returns True Anomaly of Sun in radians. rounded to 12 decimal places.



295
296
297
298
299
300
# File 'ext/calc_sun/calc_sun.c', line 295

static VALUE func_true_anomaly1(VALUE self, VALUE vajd){
  double xv = NUM2DBL(func_xv(self, vajd));
  double yv = NUM2DBL(func_yv(self, vajd));
  double vta = anp(atan2(yv, xv));
  return DBL2NUM(roundf(vta * RND12) / RND12);
}

#true_longitude1(ajd) ⇒ Object

given an Astronomical Julian Day Number returns True Longitude of Sun in radians. rounded to 12 decimal places.



310
311
312
313
314
315
316
317
# File 'ext/calc_sun/calc_sun.c', line 310

static VALUE func_true_longitude(VALUE self, VALUE vajd){
  double vml =
  NUM2DBL(func_mean_longitude(self, vajd));
  double veoc =
  NUM2DBL(func_equation_of_center(self, vajd));
  double vtl = anp(vml + veoc);
  return DBL2NUM(roundf(vtl * RND12) / RND12);
}

#xv(ajd) ⇒ Object

given an Astronomical Julian Day Number returns X component of Radius Vector in radians. rounded to 12 decimal places.



259
260
261
262
263
264
265
266
# File 'ext/calc_sun/calc_sun.c', line 259

static VALUE func_xv(VALUE self, VALUE vajd){
  double vea =
  NUM2DBL(func_eccentric_anomaly(self, vajd));
  double ve =
  NUM2DBL(func_eccentricity(self, vajd));
  double vxv = cos(vea) - ve;
  return DBL2NUM(roundf(vxv * RND12) / RND12);
}

#yv(ajd) ⇒ Object

given an Astronomical Julian Day Number returns Y component of Radius Vector in radians. rounded to 12 decimal places.



277
278
279
280
281
282
283
284
285
# File 'ext/calc_sun/calc_sun.c', line 277

static VALUE func_yv(VALUE self, VALUE vajd){
  double vea =
  NUM2DBL(func_eccentric_anomaly(self, vajd));
  double ve =
  NUM2DBL(func_eccentricity(self, vajd));
  double vyv =
  sqrt(1.0 - ve * ve) * sin(vea);
  return DBL2NUM(roundf(vyv * RND12) / RND12);
}