calc_sun 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 29357270031ecabae17fb6934c30a86b3aa49e6b
4
+ data.tar.gz: 9b95397a0a518191709c2ff26019e756c95eafdf
5
+ SHA512:
6
+ metadata.gz: c0e3bf0a00afd5b82de2ee91a342109ddaf64634907ac27d078be1b758a9e37d1f818fe04cb79adaff9a30b7ed201eddacfe3d96b1fe6be6d3e382a3fe9256f8
7
+ data.tar.gz: f337cbfd61716c4b273a1143c08598a3be4b5f3f58e3dd87f7c2a0ba513a067e5b8674081a8c595b13b582cf0388c41720b1dc59a2fe304340b2d1c7f3d5b422
checksums.yaml.gz.sig ADDED
Binary file
data/Gemfile ADDED
@@ -0,0 +1,30 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem 'hoe'
7
+ gem 'rake-compiler', '~> 0.9.3'
8
+ gem 'mustache'
9
+ gem 'rubocop'
10
+ gem 'development'
11
+ gem 'thor'
12
+ gem 'guard'
13
+ gem 'guard-rspec', require: false
14
+ gem 'minitest'
15
+ gem 'guard-minitest'
16
+ gem 'ZenTest'
17
+ gem 'rspec'
18
+ gem 'yard'
19
+ gem 'rdoc'
20
+ gem 'ffi'
21
+ gem 'simplecov'
22
+ gem 'test-unit'
23
+ gem 'shoulda'
24
+ gem 'pry'
25
+ gem 'guard-pytest'
26
+ gem 'nenv'
27
+ gem 'lumberjack'
28
+ gem 'listen'
29
+ gem 'ruby_dep', '~> 1.2.0'
30
+ end
data/History.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ === 0.1.1 / 2016-12-30
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Douglas Allen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,13 @@
1
+ History.rdoc
2
+ LICENSE.txt
3
+ Manifest.txt
4
+ Rakefile
5
+ README.rdoc
6
+ calc_sun.gemspec
7
+ ext/calc_sun/calc_sun.c
8
+ ext/calc_sun/extconf.rb
9
+ lib/calc_sun.rb
10
+ lib/calc_sun/version.rb
11
+ test/calc_sun_test.rb
12
+ example/sunriset.rb
13
+ Gemfile
data/README.rdoc ADDED
@@ -0,0 +1,89 @@
1
+
2
+ = calc_sun
3
+
4
+ Home :: https://rubygems.org/gems/calc_sun
5
+ Code :: https://github.com/DouglasAllen/calc_sun
6
+ RDoc :: http://http://www.rubydoc.info/gems/calc_sun/
7
+ Issues :: https://github.com/DouglasAllen/calc_sun/issues
8
+
9
+
10
+ == DESCRIPTION:
11
+
12
+ Calculate Sunrise and Sunset. Now uses native C extension.
13
+ An example is supplied to show gem usage.
14
+
15
+ == FEATURES/PROBLEMS:
16
+
17
+ n/a
18
+
19
+ == SYNOPSIS:
20
+
21
+ === start irb
22
+
23
+ $ irb --simple-prompt
24
+
25
+ === enter Code
26
+
27
+ require 'calc_sun'
28
+ cs = CalcSun.new
29
+ require 'date'
30
+ # not included yet for determining your mean time
31
+ DJ00 = DateTime.parse('2000-01-01T12:00:00').jd
32
+
33
+ lat = 51.4770228
34
+ lon = -0.0001147
35
+ day = Date.parse('2016-12-25')
36
+ jd = day.jd - DJ00 - lon / 360.0
37
+ cs.t_rise(jd, lon, lat)
38
+ cs.t_mid_day(jd, lon, lat)
39
+ cs.t_set(jd, lon, lat)require 'date'
40
+
41
+
42
+ == INSTALL:
43
+
44
+ $> bundle install
45
+
46
+ $> bundle exec rake install
47
+
48
+
49
+ === Build with DEVKIT
50
+
51
+ cd to devkit dir and run devkitvars.bat
52
+
53
+ or make a batchfile to start your envirnment with 'run devkitvars'
54
+ cd to calc_sun dir
55
+ Rake -T
56
+
57
+ == DEVELOPERS:
58
+
59
+ After checking out the source, run:
60
+
61
+ $ bundle exec rake newb
62
+
63
+ This task will install any missing dependencies, run the tests/specs,
64
+ and generate the RDoc.
65
+
66
+ == LICENSE:
67
+
68
+ (The MIT License)
69
+
70
+ Copyright (c) 2016
71
+
72
+ Permission is hereby granted, free of charge, to any person obtaining
73
+ a copy of this software and associated documentation files (the
74
+ 'Software'), to deal in the Software without restriction, including
75
+ without limitation the rights to use, copy, modify, merge, publish,
76
+ distribute, sublicense, and/or sell copies of the Software, and to
77
+ permit persons to whom the Software is furnished to do so, subject to
78
+ the following conditions:
79
+
80
+ The above copyright notice and this permission notice shall be
81
+ included in all copies or substantial portions of the Software.
82
+
83
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
84
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
85
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
86
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
87
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
88
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
89
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'hoe'
4
+ require 'rake/testtask'
5
+ require 'rake/extensiontask'
6
+
7
+
8
+ Hoe.plugin :manifest
9
+
10
+ Hoe.spec 'calc_sun' do
11
+ self.version = '0.1.1'
12
+ developer('kb9agt', 'kb9agt@gmail.com')
13
+ self.readme_file = 'README.rdoc'
14
+ self.history_file = 'HISTORY.rdoc'
15
+
16
+ extra_dev_deps << ['rake-compiler', '~> 0.9.3']
17
+ self.spec_extras = { extensions: ['ext/calc_sun/extconf.rb'] }
18
+
19
+ Rake::ExtensionTask.new('calc_sun', spec) do |ext|
20
+ ext.lib_dir = File.join('lib', 'calc_sun')
21
+ end
22
+ end
23
+
24
+ Rake::Task[:test].prerequisites << :compile
25
+ # vim: syntax=ruby
26
+
27
+ Rake::TestTask.new(:test) do |t|
28
+ t.libs << 'test'
29
+ t.libs << 'lib'
30
+ t.test_files = FileList['test/*_test.rb']
31
+ end
32
+
33
+ task default: :test
data/calc_sun.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'calc_sun/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'calc_sun'
8
+ spec.version = CalcSun::VERSION
9
+ spec.author = 'Douglas Allen'
10
+ spec.email = ['kb9agt@gmail.com']
11
+
12
+ spec.summary = 'Calculates Sun Times ea. rise, noon, set'
13
+ spec.description = 'supply the jd date, latitude, and longitude in the calls
14
+ to each method t_rise(jd, lon, lat),
15
+ t_mid_day(jd, lon, lat), and t_set(jd, lon, lat)'
16
+ spec.homepage = 'https://github.com/DouglasAllen/calc_sun'
17
+ spec.license = 'MIT'
18
+ require 'rake'
19
+ spec.files = FileList['lib .rb',
20
+ '[A-Z]*',
21
+ 'test/ *'].to_a
22
+ spec.extensions << 'ext/eot/extconf.rb'
23
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
+ spec.require_paths = ['lib']
25
+ spec.platform = Gem::Platform::RUBY
26
+ spec.add_development_dependency 'bundler', '~> 1.13'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rake-compiler', '~> 0.9.3'
29
+ spec.add_development_dependency 'hoe', '~> 3.12.0'
30
+ spec.add_development_dependency 'guard', '~> 2.6.1'
31
+ spec.add_development_dependency 'guard-minitest', '~> 2.3.2'
32
+ spec.add_development_dependency 'minitest', '~> 5.4.1'
33
+ end
@@ -0,0 +1,35 @@
1
+ require 'benchmark'
2
+ lib = File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'calc_sun'
5
+ cs = CalcSun.new
6
+
7
+ require 'date'
8
+ DJ00 = DateTime.parse('2000-01-01T12:00:00').jd
9
+
10
+ lat = 41.95
11
+ lon = -88.75
12
+ day = Date.parse('2016-12-25')
13
+ jd = day.jd - DJ00 - lon / 360.0
14
+ rise = cs.t_rise(jd, lon, lat)
15
+ midday = cs.t_mid_day(jd, lon, lat)
16
+ set = cs.t_set(jd, lon, lat)
17
+
18
+ printf("\n")
19
+
20
+ printf("\tSun rises \t\t\t : %2.0f:%02.0f UTC\n",
21
+ rise.floor, (rise % 1 * 60.0).floor)
22
+
23
+ printf("\tSun midday \t\t\t : %2.0f:%02.0f UTC\n",
24
+ midday.floor, ((midday % 1.0) * 60).floor)
25
+
26
+ printf("\tSun sets \t\t\t : %2.0f:%02.0f UTC\n",
27
+ set.floor, (set % 1 * 60.0).floor)
28
+
29
+ n = 1_000_000
30
+ puts 'running three method calls 1_000_000 times'
31
+ Benchmark.bm(7) do |x|
32
+ x.report('rise:') { n.times { ; cs.t_rise(jd, lon, lat); } }
33
+ x.report('midday:') { n.times { ; cs.t_mid_day(jd, lon, lat); } }
34
+ x.report('set:') { n.times { ; cs.t_set(jd, lon, lat); } }
35
+ end
@@ -0,0 +1,365 @@
1
+ #include <ruby.h>
2
+
3
+ #ifndef DBL2NUM
4
+ # define DBL2NUM(dbl) rb_float_new(dbl)
5
+ #endif
6
+
7
+ #define R2D 57.295779513082320876798154814105
8
+ #define D2R 0.017453292519943295769236907684886
9
+ #define M2PI M_PI * 2.0
10
+ #define INV24 1.0 / 24.0
11
+ #define INV360 1.0 / 360.0
12
+ #define DJ00 2451545.0
13
+
14
+ // static ID id_status;
15
+
16
+ static VALUE
17
+ t_init(VALUE self)
18
+ {
19
+ return self;
20
+ }
21
+
22
+ static VALUE
23
+ func_rev12(VALUE self, VALUE vx)
24
+ {
25
+ double x = NUM2DBL(vx);
26
+ return DBL2NUM(x - 24.0 * floor(x * INV24 + 0.5));
27
+ }
28
+
29
+ static VALUE
30
+ func_mean_anomally(VALUE self, VALUE vd)
31
+ {
32
+ double d = NUM2DBL(vd);
33
+ double vma =
34
+ fmod(
35
+ (357.5291 +
36
+ 0.98560028 * d
37
+ ) * D2R, M2PI);
38
+ return DBL2NUM(vma);
39
+ }
40
+
41
+ static VALUE
42
+ func_eccentricity(VALUE self, VALUE vd)
43
+ {
44
+ double d = NUM2DBL(vd);
45
+ double ve =
46
+ 0.016709 -
47
+ 1.151e-9 * d;
48
+ return DBL2NUM(ve);
49
+ }
50
+
51
+ static VALUE
52
+ func_equation_of_center(VALUE self, VALUE vd)
53
+ {
54
+ double vma =
55
+ NUM2DBL(func_mean_anomally(self, vd));
56
+ double ve =
57
+ NUM2DBL(func_eccentricity(self, vd));
58
+ double ve2 = ve * 2.0;
59
+ double vesqr = ve * ve;
60
+ double vesqr54 = 5.0 / 4.0 * vesqr;
61
+ double vecube12 = (vesqr * ve) / 12.0;
62
+ double veoc =
63
+ ve2 * sin(vma) +
64
+ vesqr54 * sin(2 * vma) +
65
+ vecube12 * (13.0 * sin(3 * vma) - 3.0 * sin(vma));
66
+ return DBL2NUM(veoc);
67
+ }
68
+
69
+ static VALUE
70
+ func_true_anomally(VALUE self, VALUE vd)
71
+ {
72
+ double vma =
73
+ NUM2DBL(func_mean_anomally(self, vd));
74
+ double veoc =
75
+ NUM2DBL(func_equation_of_center(self, vd));
76
+ double vta = vma + veoc;
77
+ return DBL2NUM(vta);
78
+ }
79
+
80
+ static VALUE
81
+ func_mean_longitude(VALUE self, VALUE vd)
82
+ {
83
+ double d = NUM2DBL(vd);
84
+ double vml =
85
+ fmod(
86
+ (280.4664567 +
87
+ 0.9856473601037645 * d
88
+ ) * D2R, M2PI);
89
+ return DBL2NUM(vml);
90
+ }
91
+
92
+ static VALUE
93
+ func_eccentric_anomally(VALUE self, VALUE vd)
94
+ {
95
+ double ve =
96
+ NUM2DBL(func_eccentricity(self, vd));
97
+ double vml =
98
+ NUM2DBL(func_mean_longitude(self, vd));
99
+ double vea =
100
+ vml + ve * sin(vml) * (1.0 + ve * cos(vml));
101
+ return DBL2NUM(vea);
102
+ }
103
+
104
+ static VALUE
105
+ func_obliquity_of_ecliptic(VALUE self, VALUE vd)
106
+ {
107
+ double d = NUM2DBL(vd);
108
+ double vooe =
109
+ (23.439291 - 3.563E-7 * d) * D2R;
110
+ return DBL2NUM(vooe);
111
+ }
112
+
113
+ static VALUE
114
+ func_longitude_of_perihelion(VALUE self, VALUE vd)
115
+ {
116
+ double d = NUM2DBL(vd);
117
+ double vlop =
118
+ fmod(
119
+ (282.9404 +
120
+ 4.70935e-05 * d
121
+ ) * D2R, M2PI);
122
+ return DBL2NUM(vlop);
123
+ }
124
+
125
+ static VALUE
126
+ func_xv(VALUE self, VALUE vd)
127
+ {
128
+ double vea =
129
+ NUM2DBL(func_eccentric_anomally(self, vd));
130
+ double ve =
131
+ NUM2DBL(func_eccentricity(self, vd));
132
+ double vxv = cos(vea) - ve;
133
+ return DBL2NUM(vxv);
134
+ }
135
+
136
+ static VALUE
137
+ func_yv(VALUE self, VALUE vd)
138
+ {
139
+ double vea =
140
+ NUM2DBL(func_eccentric_anomally(self, vd));
141
+ double ve =
142
+ NUM2DBL(func_eccentricity(self, vd));
143
+ double vyv =
144
+ sqrt(1.0 - ve * ve) * sin(vea);
145
+ return DBL2NUM(vyv);
146
+ }
147
+
148
+ static VALUE
149
+ func_true_longitude(VALUE self, VALUE vd)
150
+ {
151
+ double vta =
152
+ NUM2DBL(func_true_anomally(self, vd));
153
+ double vlop =
154
+ NUM2DBL(func_longitude_of_perihelion(self, vd));
155
+ double vtl =
156
+ fmod(vta + vlop, M2PI);
157
+ return DBL2NUM(vtl);
158
+ }
159
+
160
+ static VALUE
161
+ func_rv(VALUE self, VALUE vd)
162
+ {
163
+ double vxv =
164
+ NUM2DBL(func_xv(self, vd));
165
+ double vyv =
166
+ NUM2DBL(func_yv(self, vd));
167
+ double vrv =
168
+ sqrt(vxv * vxv + vyv * vyv);
169
+ return DBL2NUM(vrv);
170
+ }
171
+
172
+ static VALUE
173
+ func_ecliptic_x(VALUE self, VALUE vd)
174
+ {
175
+ double vrv =
176
+ NUM2DBL(func_rv(self, vd));
177
+ double vtl =
178
+ NUM2DBL(func_true_longitude(self, vd));
179
+ double vex = vrv * cos(vtl);
180
+ return DBL2NUM(vex);
181
+ }
182
+
183
+ static VALUE
184
+ func_ecliptic_y(VALUE self, VALUE vd)
185
+ {
186
+ double vrv =
187
+ NUM2DBL(func_rv(self, vd));
188
+ double vtl =
189
+ NUM2DBL(func_true_longitude(self, vd));
190
+ double vey = vrv * sin(vtl);
191
+ return DBL2NUM(vey);
192
+ }
193
+
194
+ static VALUE
195
+ func_right_ascension(VALUE self, VALUE vd)
196
+ {
197
+ double vey =
198
+ NUM2DBL(func_ecliptic_y(self, vd));
199
+ double vooe =
200
+ NUM2DBL(func_obliquity_of_ecliptic(self, vd));
201
+ double vex =
202
+ NUM2DBL(func_ecliptic_x(self, vd));
203
+ double vra =
204
+ fmod(atan2(vey * cos(vooe), vex) + M2PI, M2PI);
205
+ return DBL2NUM(vra * R2D / 15.0);
206
+ }
207
+
208
+ static VALUE
209
+ func_declination(VALUE self, VALUE vd)
210
+ {
211
+ double vex =
212
+ NUM2DBL(func_ecliptic_x(self, vd));
213
+ double vey =
214
+ NUM2DBL(func_ecliptic_y(self, vd));
215
+ double vooe =
216
+ NUM2DBL(func_obliquity_of_ecliptic(self, vd));
217
+ double ver = sqrt(vex * vex + vey * vey);
218
+ double vz = vey * sin(vooe);
219
+ double vdec = atan2(vz, ver);
220
+ return DBL2NUM(vdec);
221
+ }
222
+
223
+ static VALUE
224
+ func_sidetime(VALUE self, VALUE vjd)
225
+ {
226
+ double vd = NUM2DBL(vjd);
227
+ double vst =
228
+ fmod(
229
+ (180 + 357.52911 + 282.9404) +
230
+ (0.985600281725 + 4.70935E-5) * vd, 360.0);
231
+ return DBL2NUM(vst / 15.0);
232
+ }
233
+
234
+ static VALUE
235
+ func_local_sidetime(VALUE self, VALUE vjd, VALUE vlon)
236
+ {
237
+ double vst = NUM2DBL(func_sidetime(self, vjd));
238
+ double vlst = NUM2DBL(vlon) / 15.0 + 12.0 + vst;
239
+ return DBL2NUM(fmod(vlst, 24.0));
240
+ }
241
+
242
+ static VALUE
243
+ func_dlt(VALUE self, VALUE vd, VALUE vlat)
244
+ {
245
+ double vsin_alt = sin(-0.8333 * D2R);
246
+ double vlat_r = NUM2DBL(vlat) * D2R;
247
+ double vcos_lat = cos(vlat_r);
248
+ double vsin_lat = sin(vlat_r);
249
+ double vooe =
250
+ NUM2DBL(func_obliquity_of_ecliptic(self, vd));
251
+ double vtl =
252
+ NUM2DBL(func_true_longitude(self, vd));
253
+ double vsin_dec = sin(vooe) * sin(vtl);
254
+ double vcos_dec =
255
+ sqrt( 1.0 - vsin_dec * vsin_dec );
256
+ double vdl =
257
+ acos(
258
+ (vsin_alt - vsin_dec * vsin_lat) /
259
+ (vcos_dec * vcos_lat));
260
+ double vdla = vdl * R2D;
261
+ double vdlt = vdla / 15.0 * 2.0;
262
+ return DBL2NUM(vdlt);
263
+ }
264
+
265
+ static VALUE
266
+ func_diurnal_arc(VALUE self, VALUE vjd, VALUE vlat)
267
+ {
268
+ double dlt = NUM2DBL(func_dlt(self, vjd, vlat));
269
+ double da = dlt / 2.0;
270
+ return DBL2NUM(da);
271
+ }
272
+
273
+ static VALUE
274
+ func_t_south(VALUE self, VALUE vjd, VALUE vlon)
275
+ {
276
+ double lst = NUM2DBL(func_local_sidetime(self, vjd, vlon));
277
+ double ra = NUM2DBL(func_right_ascension(self, vjd));
278
+ double vx = lst - ra;
279
+ double vt = vx - 24.0 * floor(vx * INV24 + 0.5);
280
+ return DBL2NUM(12 - vt);
281
+ }
282
+
283
+ static VALUE
284
+ func_t_rise(VALUE self, VALUE vjd, VALUE vlon, VALUE vlat)
285
+ {
286
+ double ts = NUM2DBL(func_t_south(self, vjd, vlon));
287
+ double da = NUM2DBL(func_diurnal_arc(self, vjd, vlat));
288
+ return DBL2NUM(ts - da);
289
+ }
290
+
291
+ static VALUE
292
+ func_t_set(VALUE self, VALUE vjd, VALUE vlon, VALUE vlat)
293
+ {
294
+ double ts = NUM2DBL(func_t_south(self, vjd, vlon));
295
+ double da = NUM2DBL(func_diurnal_arc(self, vjd, vlat));
296
+ return DBL2NUM(ts + da);
297
+ }
298
+
299
+ static VALUE
300
+ func_t_mid_day(VALUE self, VALUE vjd, VALUE vlon, VALUE vlat)
301
+ {
302
+ double tr = NUM2DBL(func_t_rise(self, vjd, vlon, vlat));
303
+ double ts = NUM2DBL(func_t_set(self, vjd, vlon, vlat));
304
+ return DBL2NUM((tr + ts) / 2.0);
305
+ }
306
+
307
+ void Init_calc_sun(void)
308
+ {
309
+ VALUE cCalcSun =
310
+ rb_define_class("CalcSun", rb_cObject);
311
+ rb_define_method(cCalcSun, "initialize", t_init, 0);
312
+ rb_define_method(cCalcSun,
313
+ "reverse_12", func_rev12, 1);
314
+ rb_define_method(cCalcSun,
315
+ "mean_anomally", func_mean_anomally, 1);
316
+ rb_define_method(cCalcSun,
317
+ "eccentricity", func_eccentricity, 1);
318
+ rb_define_method(cCalcSun,
319
+ "equation_of_center", func_equation_of_center, 1);
320
+ rb_define_method(cCalcSun,
321
+ "true_anomally", func_true_anomally, 1);
322
+ rb_define_method(cCalcSun,
323
+ "mean_longitude", func_mean_longitude, 1);
324
+ rb_define_method(cCalcSun,
325
+ "eccentric_anomally",
326
+ func_eccentric_anomally, 1);
327
+ rb_define_method(cCalcSun,
328
+ "obliquity_of_ecliptic",
329
+ func_obliquity_of_ecliptic, 1);
330
+ rb_define_method(cCalcSun,
331
+ "longitude_of_perihelion",
332
+ func_longitude_of_perihelion, 1);
333
+ // rb_define_method(cCalcSun,
334
+ // "xv", func_xv, 1);
335
+ // rb_define_method(cCalcSun,
336
+ // "yv", func_yv, 1);
337
+ rb_define_method(cCalcSun,
338
+ "true_longitude", func_true_longitude, 1);
339
+ // rb_define_method(cCalcSun,
340
+ // "rv", func_rv, 1);
341
+ // rb_define_method(cCalcSun,
342
+ // "ecliptic_x", func_ecliptic_x, 1);
343
+ // rb_define_method(cCalcSun,
344
+ // "ecliptic_y", func_ecliptic_y, 1);
345
+ rb_define_method(cCalcSun,
346
+ "right_ascension", func_right_ascension, 1);
347
+ rb_define_method(cCalcSun,
348
+ "declination", func_declination, 1);
349
+ rb_define_method(cCalcSun,
350
+ "sidereal_time", func_sidetime, 1);
351
+ rb_define_method(cCalcSun,
352
+ "local_sidereal_time", func_local_sidetime, 2);
353
+ rb_define_method(cCalcSun,
354
+ "dlt", func_dlt, 2);
355
+ rb_define_method(cCalcSun,
356
+ "diurnal_arc", func_diurnal_arc, 2);
357
+ rb_define_method(cCalcSun,
358
+ "t_south", func_t_south, 2);
359
+ rb_define_method(cCalcSun,
360
+ "t_rise", func_t_rise, 3);
361
+ rb_define_method(cCalcSun,
362
+ "t_set", func_t_set, 3);
363
+ rb_define_method(cCalcSun,
364
+ "t_mid_day", func_t_mid_day, 3);
365
+ }
@@ -0,0 +1,4 @@
1
+ require 'mkmf'
2
+ extension_name = 'calc_sun/calc_sun'
3
+ dir_config(extension_name)
4
+ create_makefile(extension_name)
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # class file CalcSun
3
+ class CalcSun
4
+ # version 0.1.0
5
+ VERSION = '0.1.1'
6
+ end
data/lib/calc_sun.rb ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'calc_sun/version'
3
+ require 'calc_sun/calc_sun'
@@ -0,0 +1,230 @@
1
+
2
+ gem 'minitest'
3
+ require 'minitest/autorun'
4
+ require 'test/unit'
5
+ lib = File.expand_path('../../lib', __FILE__)
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+ require 'calc_sun'
8
+ #
9
+ class CalcSunTest < Minitest::Test
10
+ def test_that_it_has_a_version_number
11
+ refute_nil ::CalcSun::VERSION
12
+ end
13
+
14
+ def test_it_does_something_useful
15
+ assert false
16
+ end
17
+ end
18
+ require 'date'
19
+ #
20
+ # class TestCalcSun < MiniTest::Test
21
+ class TestCalcSun100 < Test::Unit::TestCase
22
+ def setup
23
+ @t = CalcSun.new
24
+ @t_ajd = 0.0
25
+ @t_lat = 0.0
26
+ @t_lon = 0.0
27
+ end
28
+
29
+ def test_mean_anomaly
30
+ assert_equal(
31
+ 6.240059966692,
32
+ @t.mean_anomaly(@t_ajd).round(12)
33
+ )
34
+ end
35
+
36
+ def test_eccentricity
37
+ assert_equal(
38
+ 0.016709,
39
+ @t.eccentricity(@t_ajd)
40
+ )
41
+ end
42
+
43
+ def test_equation_of_center
44
+ assert_equal(
45
+ -0.001471380867,
46
+ @t.equation_of_center(@t_ajd).round(12)
47
+ )
48
+ end
49
+
50
+ def test_true_anomaly
51
+ assert_equal(
52
+ 6.238588585825,
53
+ @t.true_anomaly(@t_ajd).round(12)
54
+ )
55
+ end
56
+
57
+ def test_mean_longitude
58
+ assert_equal(
59
+ 4.895063110817,
60
+ @t.mean_longitude(@t_ajd).round(12)
61
+ )
62
+ end
63
+
64
+ def test_eccentric_anomaly
65
+ assert_equal(
66
+ 4.878582250862,
67
+ @t.eccentric_anomaly(@t_ajd).round(12)
68
+ )
69
+ end
70
+
71
+ def test_obliquity_of_ecliptic
72
+ assert_equal(
73
+ 0.409092802283,
74
+ @t.obliquity_of_ecliptic(@t_ajd).round(12)
75
+ )
76
+ end
77
+
78
+ def test_xv
79
+ assert_equal(
80
+ 0.148720277673,
81
+ @t.xv(@t_ajd).round(12)
82
+ )
83
+ end
84
+
85
+ def test_yv
86
+ assert_equal(
87
+ -0.986083974099,
88
+ @t.yv(@t_ajd).round(12)
89
+ )
90
+ end
91
+
92
+ def test_longitude_of_perihelion
93
+ assert_equal(
94
+ 4.93824156691,
95
+ @t.longitude_of_perihelion(@t_ajd).round(12)
96
+ )
97
+ end
98
+
99
+ def test_true_longitude
100
+ assert_equal(
101
+ 4.893644845555,
102
+ @t.true_longitude(@t_ajd).round(12)
103
+ )
104
+ end
105
+
106
+ def test_rv
107
+ assert_equal(
108
+ 0.997235842199,
109
+ @t.rv(@t_ajd).round(12)
110
+ )
111
+ end
112
+ end
113
+
114
+ #
115
+ class TestCalcSun200 < Test::Unit::TestCase
116
+ def setup
117
+ @t = CalcSun.new
118
+ @t_ajd = 0.0
119
+ @t_lat = 0.0
120
+ @t_lon = 0.0
121
+ end
122
+
123
+ def test_ecliptic_x
124
+ assert_equal(
125
+ 0.17976672602,
126
+ @t.ecliptic_x(@t_ajd).round(12)
127
+ )
128
+ end
129
+
130
+ def test_ecliptic_y
131
+ assert_equal(
132
+ -0.980899204395,
133
+ @t.ecliptic_y(@t_ajd).round(12)
134
+ )
135
+ end
136
+
137
+ def test_right_ascension
138
+ assert_equal(
139
+ 18.753078192426,
140
+ @t.right_ascension(@t_ajd).round(12)
141
+ )
142
+ end
143
+
144
+ def test_declination
145
+ assert_equal(
146
+ -0.372949956542,
147
+ @t.declination(@t_ajd).round(12)
148
+ )
149
+ end
150
+
151
+ def test_sidereal_time
152
+ assert_equal(
153
+ 6.697967333333,
154
+ @t.sidereal_time(@t_ajd).round(12)
155
+ )
156
+ end
157
+
158
+ def test_local_sidereal_time
159
+ assert_equal(
160
+ 18.697967333333,
161
+ @t.local_sidereal_time(@t_ajd, @t_lon).round(12)
162
+ )
163
+ end
164
+
165
+ def test_dlt
166
+ assert_equal(
167
+ 12.120732161881,
168
+ @t.dlt(@t_ajd, @t_lat).round(12)
169
+ )
170
+ end
171
+
172
+ def test_diurnal_arc
173
+ assert_equal(
174
+ 6.06036608094,
175
+ @t.diurnal_arc(@t_ajd, @t_lat).round(12)
176
+ )
177
+ end
178
+
179
+ def test_t_south
180
+ assert_equal(
181
+ 12.055110859092,
182
+ @t.t_south(@t_ajd, @t_lon).round(12)
183
+ )
184
+ end
185
+
186
+ def test_t_rise
187
+ assert_equal(
188
+ 5.994744778152,
189
+ @t.t_rise(@t_ajd, @t_lon, @t_lat).round(12)
190
+ )
191
+ end
192
+
193
+ def test_t_mid_day
194
+ assert_equal(
195
+ 12.055110859092,
196
+ @t.t_mid_day(@t_ajd, @t_lon, @t_lat).round(12)
197
+ )
198
+ end
199
+
200
+ def test_t_set
201
+ assert_equal(
202
+ 18.115476940033,
203
+ @t.t_set(@t_ajd, @t_lon, @t_lat).round(12)
204
+ )
205
+ end
206
+
207
+ def test_rise_time
208
+ rise = @t.t_rise(@t_ajd, @t_lon, @t_lat).round(12)
209
+ assert_equal(
210
+ "Sun rises \t\t\t : 5:59 UTC",
211
+ "Sun rises \t\t\t : #{rise.floor}:#{(rise % 1 * 60.0).floor} UTC"
212
+ )
213
+ end
214
+
215
+ def test_midday_time
216
+ midday = @t.t_mid_day(@t_ajd, @t_lon, @t_lat).round(12)
217
+ assert_equal(
218
+ "Sun mid day \t\t\t : 12:3 UTC",
219
+ "Sun mid day \t\t\t : #{midday.floor}:#{((midday % 1.0) * 60).floor} UTC"
220
+ )
221
+ end
222
+
223
+ def test_set_time
224
+ set = @t.t_set(@t_ajd, @t_lon, @t_lat).round(12)
225
+ assert_equal(
226
+ "Sun sets \t\t\t : 18:6 UTC",
227
+ "Sun sets \t\t\t : #{set.floor}:#{(set % 1 * 60.0).floor} UTC"
228
+ )
229
+ end
230
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: calc_sun
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - kb9agt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDaDCCAlCgAwIBAgIBATANBgkqhkiG9w0BAQUFADA9MQ8wDQYDVQQDDAZrYjlh
14
+ Z3QxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2NvbTAe
15
+ Fw0xNjEyMzAwNDMxMDhaFw0xNzEyMzAwNDMxMDhaMD0xDzANBgNVBAMMBmtiOWFn
16
+ dDEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29tMIIB
17
+ IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwUJbvvbjVVV2ftkL3R7RcRSO
18
+ 6Mosw9c6vKViXLyKIXyzkXIwtxoygdNj8/WE2Ld/bxxp/tnSeOno1gMWpU5NqpKn
19
+ FS7+Rd/ihkHa0JUh5of6o+p9MmHVc+e3AZPVRrdq24P9465mTkQRx2j50c3mPmGO
20
+ AW9gT93A/BJtp91KSpExQmJ6VN0I7AxGYodlegRDJRw4o8Ap5WS8GHjOdpZSKbyq
21
+ ipD303lPvWEnp9Yra+VzqUXsIdSGVG+As78npWxIn8fZDX2OsYT2qyctYvJiSsqB
22
+ xMfaBX8VjWPDf3LP3LgLBpUzCGL9KV4iLtcuZaz0OgE9BahA7Kp2T1OjP4fbcQID
23
+ AQABo3MwcTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUAEuv016V
24
+ 8m/v3zAssXTNrfv76QAwGwYDVR0RBBQwEoEQa2I5YWd0QGdtYWlsLmNvbTAbBgNV
25
+ HRIEFDASgRBrYjlhZ3RAZ21haWwuY29tMA0GCSqGSIb3DQEBBQUAA4IBAQAXLnar
26
+ /NKG0Wf2KjYnjPFu3+B+2O6z83VYLp6WqtH6YHpGmYYaYIEpIOOVzwZnG3LVJacj
27
+ XR+KyspHMyq/7wGmCFzcaUAb77zknqOkpSYVKlRZRdgtJ6oDMIwFFZN9Xwdg7mMj
28
+ yMevwJb6U/d+XQC8FFxMJsL2u1a5jl1jXo3Sv6ZUxEhlNJSFOsFFQqTfR8Sq8kMm
29
+ 9tEcHmnS7RQS2IQzljk++ha4q0G+qqZz81bjEX0mE6wGYz7mda6lJ40mUKyfA1KH
30
+ J4L8DCnzZFU8ARwINSdPvhk8WzXpVgErPQezTziVg7gAtBjqdJO5qVlAiOp+z7m2
31
+ gT57pae1qMGtqvMp
32
+ -----END CERTIFICATE-----
33
+ date: 2016-12-30 00:00:00.000000000 Z
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake-compiler
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.9.3
42
+ type: :development
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 0.9.3
49
+ - !ruby/object:Gem::Dependency
50
+ name: rdoc
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '4.0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '4.0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: hoe
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.15'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.15'
77
+ description: |-
78
+ Calculate Sunrise and Sunset. Now uses native C extension.
79
+ An example is supplied to show gem usage.
80
+ email:
81
+ - kb9agt@gmail.com
82
+ executables: []
83
+ extensions:
84
+ - ext/calc_sun/extconf.rb
85
+ extra_rdoc_files:
86
+ - History.rdoc
87
+ - LICENSE.txt
88
+ - Manifest.txt
89
+ - README.rdoc
90
+ files:
91
+ - Gemfile
92
+ - History.rdoc
93
+ - LICENSE.txt
94
+ - Manifest.txt
95
+ - README.rdoc
96
+ - Rakefile
97
+ - calc_sun.gemspec
98
+ - example/sunriset.rb
99
+ - ext/calc_sun/calc_sun.c
100
+ - ext/calc_sun/extconf.rb
101
+ - lib/calc_sun.rb
102
+ - lib/calc_sun/version.rb
103
+ - test/calc_sun_test.rb
104
+ homepage: https://rubygems.org/gems/calc_sun
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options:
110
+ - "--main"
111
+ - README.rdoc
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.6.8
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Calculate Sunrise and Sunset
130
+ test_files: []
metadata.gz.sig ADDED
Binary file